简体   繁体   English

IE6中的Javascript代码错误

[英]Javascript code error in IE6

I have this piece of code on a php page, at the bottom: 我在底部的php页面上有这段代码:

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). 这似乎在IE6中不起作用(尚未测试任何其他IE版本)。

It works fine in FF, Safari, Opera, Chrome etc... But as usual, IE struggles. 它可以在FF,Safari,Opera,Chrome等环境下正常工作。但是,与往常一样,IE仍在努力。

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? 我收到的错误消息是: “'Window.opener.location'为null或不是对象”对此有任何解决方法吗?

If you need more input let me know. 如果您需要更多输入,请告诉我。 Thanks 谢谢

BTW: I have tried changing the path back and forth... no help 顺便说一句:我试图来回改变路径……没有帮助

Did you try without the href? 您是否尝试过没有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. 而且,无论如何,您都应该检查null值和undefined值,具体取决于您的设置,但始终将其保留在其中不会有任何危害,并且打开器可能已关闭。

[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. [除了:我还会对IE6的使用提出一个大问题,以我的经验,这将在大多数Web项目中增加JS和CSS问题方面的成本。 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.] 甚至(根据我的经验,大多数(再次),将其列为必不可少的客户也将最终屈服并升级到IE7或更高版本,直到他们看到IE6规定的费用占了多少。]

...
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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM