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.
3 Answers
Reset to default 2After 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();
}