最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - window.opener.location not working in IE - Stack Overflow

programmeradmin2浏览0评论

I'm trying to redirect from child page to parent page with this 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:

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

alert(window.opener) returns null in IE 9.

I'm trying to redirect from child page to parent page with this 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:

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

alert(window.opener) returns null in IE 9.

Share Improve this question asked Nov 20, 2012 at 13:29 benjamin54benjamin54 1,3004 gold badges28 silver badges50 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

After searching for quite a while I have found the solution for internet explorer. You need to use

window.opener.location.href='';

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.

I think you can use 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();
}
发布评论

评论列表(0)

  1. 暂无评论