javascript window.opener.location 在 IE 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13474287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.opener.location not working in IE
提问by benjamin54
I'm trying to redirect from child page to parent page with this javascript:
我正在尝试使用此 javascript 从子页面重定向到父页面:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close", "ClosePopUp();", true);
<script language="javascript" type="text/javascript">
function ClosePopUp() {
window.opener.location= 'ParentPage.aspx';
self.close();
}
</script>
It works with Firefox & Chrome. But not with IE 9. The error I'm getting is:
它适用于 Firefox 和 Chrome。但不适用于 IE 9。我得到的错误是:
Unable to get value of the property 'location': object is null or undefined
Unable to get value of the property 'location': object is null or undefined
alert(window.opener)
returns null
in IE 9.
alert(window.opener)
null
在 IE 9 中返回。
采纳答案by David Hellsing
window.opener
is a non-standard property and is not available in all browsers. It will also evaluate to null
if the window wasn't opened from another window, so it seems pretty unreliable.
window.opener
是一个非标准属性,并非在所有浏览器中都可用。它还将评估null
该窗口是否不是从另一个窗口打开的,因此它看起来非常不可靠。
回答by logistef
After searching for quite a while I have found the solution for internet explorer. You need to use
经过一段时间的搜索,我找到了 Internet Explorer 的解决方案。你需要使用
window.opener.location.href='';
window.opener.location.href='';
回答by Bruno
I think you can use window.open
我想你可以使用 window.open
window.open(URL,name,specs,replace)
More info here
更多信息在这里
Update
更新
I think I have got it now. Add an eventhandler in your parent window to your child's unload event.
我想我现在已经明白了。在您的父窗口中将一个事件处理程序添加到您孩子的卸载事件中。
var win = window.open("ChildPage.aspx");
function popUpUnLoaded() {
window.location = "ParentPage.aspx";
}
if (typeof win.attachEvent != "undefined") {
win.attachEvent("onunload", popUpUnLoaded );
} else if (typeof win.addEventListener != "undefined") {
win.addEventListener("unload", popUpUnLoaded, false);
}
This means that when the function below executes your parent page picks up on it.
这意味着当下面的函数执行时,您的父页面会接收它。
function ClosePopUp() {
self.close();
}