[英]IE: Unset window.opener
I am trying to check whether a window on my site can be closed with: 我正在尝试检查是否可以通过以下方式关闭我网站上的窗口:
if (window.opener && window.opener.closed === false) {
It is possible for users to reach my site via another window that sets window.opener
. 用户可以通过另一个设置window.opener
窗口访问我的网站。 I can "reset" window.opener
when users initially reach my site using: window.opener = null
. 当用户最初使用以下方式访问我的网站时,我可以“重置” window.opener
: window.opener = null
。 However, this doesn't work in IE (on the next page, window.opener
is restored). 但是,这在IE中不起作用(在下一页,将还原window.opener
)。
Is there a way to "reset" the window.opener
construct in IE, or another cross-browser solution to my problem in general? 有没有一种方法可以在IE中“重置” window.opener
构造,或者是一般情况下解决我的问题的另一个跨浏览器解决方案?
I found a solution that's not totally analogous, but will work for my purposes. 我发现了一个不完全相似的解决方案,但可以满足我的目的。 I only want to close the window if the opener is from the same domain. 如果启动器来自同一域,我只想关闭窗口。
if (window.opener.location.hostname.indexOf(window.location.hostname) > -1) {
However, IE does not allow you to access window.opener.location
if the opener is from a different host. 但是,如果打开器来自其他主机,则IE不允许您访问window.opener.location
。 This actually works out quite well: 这实际上效果很好:
try {
//snippet above
}
catch (error) { /* no action needed; assume different host */ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.