window.showModalDialog(URL,dialogArgments.features) 打開一個新窗口
URL為要開啟的網頁名字。
dialogArgments為設定好傳遞給新視窗網頁的參數,可以為任意數據類型。
feature 與open()的類似,都是格式方面的設定。調用格式為featureName1:featureValue1:(分號)featureName2:featureValue2:
關于feature具體的參數我就不詳細寫了,看名字就應該知道什么用處了吧。
certer , dialogHeight, dialogLeft,dialogTop,dialogWidth,help(是否顯示help按鈕,下同),status,resizeable
值=1為yes,0為no.
我認為最重要的是dialogArgments,可以傳遞值到新的窗口。
第二重要就是 它的返回值 window.returnValue.可以在showModalDialog開啟的窗口關閉后前,回傳一個任意類型的值。
dialogArgments 可以傳入一個變量,但是 我認為最好是傳入一個window 這樣的話,不光你可以調用你前面定義的變量names 和a 等等,還可以取到前一個頁面上任何元素的值.如下面的代碼所示:

<script language =javascript>
alert(window.dialogArguments.names);
alert(window.dialogArguments.a );
// alert(window.dialogArguments.document.form1.t1.value)
window.dialogArguments.a = "Hello World"; //可以改變WebFromA里面的變量的值
window.dialogArguments.document.form1.t1.value = "t1";//可以修改WebFrom1里面的TextBox的value;
在WebFromB.aspx頁面 我們可以取到 names 和a 的值還可以取到WebFromA的值.,還可以給它賦值.
整體的代碼如下:
WebFromA.aspx

<%
@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormA.aspx.cs" Inherits="_5demo.ShowDig.WebFormA" %>

<!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>

<script language=javascript>
function fnA()

{
names = new Array(3);
names[0] = "chenzhifeng";
names[1] = "chenjiang";
a= "shuhui";
temp= window.showModalDialog("WebFormB.aspx",window);
// alert(a);
document.getElementById("t3").value = temp;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type=text value ="feng" id = "t1" />
<br />
<input type=text value ="chen" id = "t2" />
<input type=button value = "Click Me" onclick ="fnA();" id = "btn1" />
<p>
返回值:<input type = "text" id= "t3" />
</div>
</form>
</body>
</html>

WebFormB.aspx 如下:

<%
@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormB.aspx.cs" Inherits="_5demo.ShowDig.WebFormB" %>

<!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>

<script language =javascript>
// alert(window.dialogArguments.names);
alert(window.dialogArguments.a );
// alert(window.dialogArguments.document.form1.t1.value)
window.dialogArguments.a = "Hello World"; //可以改變WebFromA里面的變量的值
window.dialogArguments.document.form1.t1.value = "t1";//可以修改WebFrom1里面的TextBox的value;
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type=text id = "tt" value = "Hello ZiFeng"/>

<script language =javascript>
window.returnValue = document.getElementById("tt").value;
window.close();
</script>
</div>
</form>
</body>
</html>

在WebFormB.aspx中 window.returnValue是用于 返回給WebFromA.aspx的值.
在WebFromA.aspx中,可以用一個變量來接收這個值 temp= window.showModalDialog("WebFormB.aspx",window);
J-CN工作室
www.j-cn.org