一:父頁面js取得彈出視窗值
本頁面用一個textbox接受傳值
<input id="Text1" type="text" οnclick="show();" runat="server" />
function show()
{
var result= window.showModalDialog("top.aspx",null,"dialogWidth:350px;dialogHeight:350px;help:no;status:no");
if (result)
{
var a = document.getElementById("Text1");
a.value=result;
//alert(result);
}
else
{
alert('子視窗傳回假!');
}
}
彈出視窗頁面
在頁面添加 <base target="_self"></base>
傳回傳值用
string a = "傳值成功";
Response.Write( "<script>window.returnValue='" +a+ "';window.close();</script>" );
二:彈出視窗關閉,重新整理父頁面
父頁面
<script type="text/javascript">
function show()
{
//彈出視窗方法1:
//window.showModalDialog("Default3.aspx",null,"dialogWidth:350px;dialogHeight:350px;help:no;status:no");
//彈出視窗方法2:
window.open("Default3.aspx",null,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=200,left=300,top=400");
/ }
</script>
彈出頁面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>無标題頁</title>
<base target="_self"></base>
</head>
<body >
<form id="form1" runat="server">
<div>
彈出頁面
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" /></div>
</form>
</body>
</html>
代碼:
protected void Button2_Click( object sender, EventArgs e )
{
Response.Write( "<script>window.opener.location.reload();window.close();</script>" );
}
重新整理架構父頁面
Response.Write("<script>window.open('err.aspx','');window.parent.location.reload();</script>");
轉載于:https://www.cnblogs.com/Magicam/archive/2008/12/14/1354623.html