我正在尝试使用此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>
适用于Firefox&amp;铬。但不是IE 9。 我得到的错误是:
Unable to get value of the property 'location': object is null or undefined
alert(window.opener)
在IE 9中返回null
。
答案 0 :(得分:2)
经过一段时间的搜索,我找到了Internet Explorer的解决方案。 你需要使用
window.opener.location.href = '';
答案 1 :(得分:1)
window.opener
是非标准媒体资源,并非在所有浏览器中都可用。如果窗口没有从另一个窗口打开,它也会评估为null
,所以它似乎非常不可靠。
答案 2 :(得分:0)
我认为你可以使用window.open
window.open(URL,name,specs,replace)
更多信息here
<强>更新强>
我想我现在已经得到了。在父窗口中添加一个eventhandler给孩子的卸载事件。
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);
}
这意味着当下面的函数执行时,您的父页面会选中它。
function ClosePopUp() {
self.close();
}