簡體   English   中英

window.opener.location 在 IE 中不起作用

[英]window.opener.location not working in IE

我正在嘗試使用此 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 和 Chrome。 但不適用於 IE 9。我得到的錯誤是:

Unable to get value of the property 'location': object is null or undefined

alert(window.opener)在 IE 9 中返回null

經過一段時間的搜索,我找到了 Internet Explorer 的解決方案。 你需要使用

window.opener.location.href='';

window.opener是一個非標准屬性,並非在所有瀏覽器中都可用。 如果該窗口不是從另一個窗口打開的,它也會評估為null ,因此它看起來非常不可靠。

我想你可以使用 window.open

window.open(URL,name,specs,replace)

更多信息在這里

更新

我想我現在已經明白了。 在您的父窗口中將一個事件處理程序添加到您孩子的卸載事件中。

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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM