views:

54

answers:

1

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

+1  A: 

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
Dara
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.
Gary
Thanks, I'm using the stack a while, but want to start voting on good content I find, so now I have to hunt unanswered questions just to get kudos to give kudos. Hard work ;) And this, I have solved just this issue before (if I'm reading it right) so I just hope my memory is serving me well! Thanks for the comment and +!
Dara