0

I have this piece of code on a php page, at the bottom:

window.opener.location.href="/index.html";
setTimeout("self.close();",3000);

This doesn't seem to work in IE6 (haven't tested any other IE version yet).

It works fine in FF, Safari, Opera, Chrome etc... But as usual, IE struggles.

So, what could be the problem.

The error message I get is: "'Window.opener.location' is null or not an object" Is there any walkaround for this?

If you need more input let me know. Thanks

BTW: I have tried changing the path back and forth... no help

3
  • I didn't understand properly what you are trying to do, it seems to me you want to open a new window, in such a case you need to use window.open method call and NOT window.opener property. You can use window.open to open a new window, then in the newly opened window, you can access the original window by using window.opener. Commented Aug 26, 2010 at 16:51
  • 1
    @Marco: He's calling this code from within the popup. He's trying to redirect the opener window to a new page and then close the popup window. Commented Aug 26, 2010 at 16:56
  • @theycallmemorty: ok, but he did not mention this, so it sounded strange. I was basically trying to understand more. So the new window pops up, it might be that IE6 closed the parent window while opening the popup window for a security issue (or any other IE6 strange error), Camran could you explain more. Commented Aug 26, 2010 at 17:01

1 Answer 1

1

Did you try without the href?

And you should be checking for null anyway and undefined depending on your setup perhaps but no harm to have it always in there, and the opener may have been closed.

[Aside : I would also put a big question on use of IE6, it will add serious cost in terms of JS and CSS issues in most web projects, in my experience. Even (most - again, in my experience) clients who list it as a must will eventually cave in and upgrade to IE7 or later when they see how much of the costs the IE6 stipulation is accounting for.]

...
var target="/relative/path";
...
if(opener===null||opener===undefined||opener.closed){
  opener=window.open(target); // our opener is gone or unavailable, go with new (or could set a warning/error here, etc)
}
else{
  opener.location=target; // redirect the opener
}
...
//set timeout to close popup here
Sign up to request clarification or add additional context in comments.

1 Comment

Welcome to StackOverflow. You'll soon realize it's really difficult to provide answers without the comment ability and that other users don't give votes for free. Here is a +1 to help you get started. Also your answer kind of makes sense so you deserve it anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.