父窗體:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>父窗口</title>
</head>
<body>
<span onclick="window.open('z.htm')" style="cursor:hand;">打開子窗口</span>
</body>
</html>
子窗體:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>子窗口</title>
<script language="javascript">...
function closethewindow()
...{
var url="f.htm";//要刷新的窗口
opener.document.location=url;
window.close();
}
</script>
</head>
<body>
<span onclick="closethewindow();" style="cursor:hand;">關閉子窗口,刷新父窗口</span><br />
<span onclick="javascript:window.location.reload();" style="cursor:hand;">刷新此窗口</span>
</body>
</html>
asp.net
父窗口彈出子窗口的 button處理事件:
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("<script language=javascript>window.open('WebForm1.aspx','', 'alwaysRaised=1,dependent=1,resizable=0,scrollbars,width=450,height=550');</script>");
}
//父窗口html代碼添加如下javascript代碼
<script language="javascript">
function refresh()
{
this.location = this.location;
}
</script>
//子窗口關閉窗口的 button處理事件:
private void Button1_Click(object sender, System.EventArgs e)
{
StringBuilder scriptString = new StringBuilder();
scriptString.Append("<script language = javascript>");
scriptString.Append("window.opener.refresh();");
scriptString.Append( " window.focus();" );
scriptString.Append( " window.opener=null;" );
scriptString.Append( " window.close(); " );
scriptString.Append("</"+"script>");
Response.Write(scriptString.ToString());
// Response.Write("<script language=javascript>window.close()</script>");
}
其它可以參考的網頁:
http://dev.csdn.net/article/48935.shtm
http://blog.csdn.net/blackhero/archive/2005/06/23/401000.aspx