问题描述
我在Internet Explorer 8中有以下代码:
I have the following code in Internet Explorer 8:
if (window.opener != null && window.opener.foo != null) window.opener.foo = bar;
有时, window.opener
已设置。但是如果用户打开弹出窗口然后导航,则应该避免尝试在其上设置属性。
Sometimes, window.opener
is set. But if users open a popup and then navigate away, the attempt to set a property on it should be avoided.
在Firefox和Chrome中,这是有效的,因为<$ c一旦用户退出或刷新该窗口,$ c> window.opener 就变为null。但是,在IE中, window.opener
不为空,而 window.opener.foo
则改为Permission Denied为null。因此, window.opener.foo!= null
的计算结果为真。
In Firefox and Chrome, this works, because window.opener
becomes null once the user exits or refreshes that window. In IE, however, window.opener
is not null, and window.opener.foo
gives "Permission Denied" instead of null. Because of this, window.opener.foo != null
evaluates to true.
我如何解决这个问题问题,什么值匹配Internet Explorer中的Permission Denied?
How do I get around this problem, what value matches "Permission Denied" in Internet Explorer?
推荐答案
这是我在IE8中使用的检查:
This is the check I use in IE8:
if (window.opener && !window.opener.closed) {
// do what you will with window.opener
}
编辑:如果你想显示一个友好的错误,你可以尝试类似这样的事情:
if you want to display a friendly error, you can try something like this:
try {
if (window.opener && window.opener.foo != null) {
window.opener.foo = bar;
}
} catch (e) {
if (e.description.toLowerCase().indexOf('permission denied') !== -1) {
// handle it nicely
} else {
// some other problem, let it blow up
throw e;
}
}
这使您可以专门处理拒绝访问错误,但没有隐藏任何其他潜在的错误。
This allows you to specifically handle the "Access Denied" error, while not hiding any other potential errors.
这篇关于Internet Explorer - 检查权限是否被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!