Refresh Parent Window in IE

Refresh Parent Window in IE

MainWindow:

<SCRIPT language="JavaScript" type="text/javascript">
function popup(url)
{
popwin = window.open (url, "www.5d8.cn", "location=0,status=0,scrollbars=0,width=400,height=500");
popwin .moveTo(50,100);
}

function doRefresh()
{
window.location.reload();
}
</SCRIPT>

PopWindow:

<script language="JavaScript" type="text/javascript">
window.onunload=function() //event fire each post back
{
window.opener.doRefresh()
}
</script>


javascript event when close a window
http://forums.devshed.com/html-programming-1/how-to-trap-window-close-event-of-browser-in-ie-1503.html

// Only when user don't click F5 for refresh - -~
window.onbeforeunload=function()
{
if(window.event.clientY)
}

// Looks only work with pop-ups
if(window.screenTop > 10000)
alert("Window is closed");
else
alert("Window stillOpen");

Another way:
Put your page in a frame.
When post back. The frame won't fire onunload.
When close. It fire.
So we can put the function in onunload of the frame.

If you don't want to update parent window unless special button is clicked.
You can add statement in codebehind like:
protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "RefreshOpener", "<script language='JavaScript' type='text/javascript'>window.opener.doRefresh();</script>");
//this.RegisterStartupScript("RefreshOpener", "<script language='JavaScript' type='text/javascript'>window.opener.doRefresh();</script>");
}

你可能感兴趣的:(JavaScript,html,IE)