在B/S模式的应用项目,我们有可能要处理一些的模式对话框。
在Javascript中的主要是用得了window.showmodeldialog方法
关于Window.dialogarguments 参数主要是用来一个页面发起一个模式对话框页面,该模式页面利用Window.dialogarguments将该页面中的对象或其它的值传回给发起页面中桥梁作用。window.dialogArguments 即为父窗口window对象的引用
例如:
A 用window.showModalDialog()打开了B,B 用window.dialogArguments[0].open()打开了C,请问C关闭时怎么刷新B ?
1
2
3
4 例子
5 1.htm
6 ===========
7 <title>1</title>
8 <input type=button value="open 2" onclick="window.showModalDialog('2.htm',window);">
9 <script>
10 alert("1")
11 </script>
12
13
14 2.htm
15 ===========
16 <title>2</title>
17 <frameset cols="0,*">
18 <frame src="">
19 <frame src="b.htm">
20 </frameset>
21
22 b.htm
23 ==========
24 <input type=button value="open 3" onclick="window.showModalDialog('3.htm',window);">
25 <script>
26 alert("我是2")
27 </script>
28
29
30 3.htm
31 =========
32 <title>3</title>
33 <frameset cols="0,*">
34 <frame src="">
35 <frame src="c.htm" name="x">
36 </frameset>
37
38
39 c.htm
40 =====
41 <input type="button" value="refresh 2 and close me" onclick="window.dialogArguments.location='2.htm';window.parent.close()">
42
43
44 注意:showModalDialog缓存的厉害,请清空缓存每次测试
转自:
window.dialogArguments的使用,回调上级页面
1 上级页面:showModelessDialogEX.htm
2 <HTML>
3 <HEAD>
4 <TITLE>showModelessDialogEX.htm</TITLE>
5 <SCRIPT>
6 var sUserName="";
7
8 function fnCallDialog(){
9 showModelessDialog("myDialog.htm",window,"status:false;dialogWidth:300px;dialogHeight:300px");
10 }
11
12 function fnUpdate(){
13 oName.innerText = sUserName;
14 }
15 </SCRIPT>
16 </HEAD><BODY>
17 <P>Enter your first name:
18 <SPAN ID="oName" STYLE="color:red;font-size:24">Joan</SPAN></P>
19 <INPUT TYPE="button"
20 VALUE="Display Modeless Dialog" onclick="fnCallDialog()">
21 </BODY>
22 </HTML>
23
24 弹出页面:myDialog.htm
25 <HTML>
26 <HEAD>
27 <TITLE>myDialog.htm</TITLE>
28 <SCRIPT>
29 function fnGetInfo() {
30 var sData = dialogArguments;
31 sData.sUserName = oEnterName.value;
32 sData.fnUpdate();
33 }
34 function fnCancel() {
35 var sData = dialogArguments;
36 sData.sUserName = "Joan";
37 sData.fnUpdate();
38 }
39 </SCRIPT>
40 </HEAD>
41 <BODY>
42 <LABEL FOR="oEnterName" ACCESSKEY="f">
43 Enter your <SPAN STYLE="text-decoration:underline">F</SPAN>irst Name</LABEL>
44 <INPUT ID=oEnterName><BR><BR>
45 <INPUT VALUE="Apply" TYPE=button onclick="fnGetInfo();">
46 <INPUT VALUE="Ok" TYPE=button onclick="fnGetInfo();window.close();">
47 <INPUT VALUE="Cancel" TYPE=button onclick="fnCancel();window.close();">
48 </BODY>
49 </HTML>
50
51 其中myDialog.htm页面回调showModelessDialogEX.htm页面的fnUpdate(),进行数据更改操作。
52
53 项目中用到的一个方法:
54
55 function sendBackSign(){
56 if(!onCheck()) return;
57 window.dialogArguments[0].signContentPara ="&signTitle="+SignSheetForm.signTitle.value
58 +"&signContent="+SignSheetForm.signContent.value
59 +"&signPersonCuid="+SignSheetForm.signPersonCuid.value
60 +"&signTime="+SignSheetForm.signTime.value;
61 window.dialogArguments[0].sendBack();
62 window.close();
63 }
64 function closeWin(){
65 window.close();
66 }
67
68 这里回调上级页面的sendBack()方法
使用:
window.dialogArguments的使用
1 window.dialogArguments的使用
2 <HTML>
3
4 <HEAD>
5
6 <TITLE>showModelessDialogEX.htm</TITLE>
7
8 <SCRIPT>
9
10 var sUserName="";
11
12 function fnCallDialog(){
13
14 showModelessDialog("myDialog.htm",window,"status:false;dialogWidth:300px;dialogHeight:300px");
15
16 }
17
18 function fnUpdate(){
19
20 oName.innerText = sUserName;
21
22 }
23
24 </SCRIPT>
25
26 </HEAD>
27
28 <BODY>
29
30 <P>Enter your first name: <SPAN ID="oName" STYLE="color:red;font-size:24">Joan</SPAN></P>
31
32 <INPUT TYPE="button" VALUE="Display Modeless Dialog" onclick="fnCallDialog()">
33
34 </BODY>
35
36 </HTML>
37
38
39 Here is the code for "myDialog.htm".
40
41
42 <HTML>
43 <HEAD>
44 <TITLE>myDialog.htm</TITLE>
45 <SCRIPT>
46 function fnGetInfo() {
47 var sData = dialogArguments;
48 sData.sUserName = oEnterName.value;
49 sData.fnUpdate();
50 }
51 function fnCancel() {
52 var sData = dialogArguments;
53 sData.sUserName = "Joan";
54 sData.fnUpdate();
55 }
56 </SCRIPT>
57 </HEAD>
58 <BODY>
59 <LABEL FOR="oEnterName" ACCESSKEY="f">
60 Enter your <SPAN STYLE="text-decoration:underline">F</SPAN>irst Name</LABEL>
61 <INPUT ID=oEnterName><BR><BR>
62 <INPUT VALUE="Apply" TYPE=button onclick="fnGetInfo();">
63 <INPUT VALUE="Ok" TYPE=button onclick="fnGetInfo();window.close();">
64 <INPUT VALUE="Cancel" TYPE=button onclick="fnCancel();window.close();">
65 </BODY>
66 </HTML>
67
68 dialogArguments只能在mode和modeless窗口中才能使用,可以传递传递任意类型的值,
69 上例就是传得失window. 在以前的项目中,页面之间传递参数经常使用的是url后接参数的形式,
70 现在终于发现dialogArguments不愧为更好的方法。
使用收藏:
window.dialogArguments的使用收藏
1 showModelessDialogEX.htm
2
3 <HTML>
4 <HEAD>
5 <TITLE>showModelessDialogEX.htm</TITLE>
6 <SCRIPT>var sUserName="";function fnCallDialog(){ showModelessDialog("myDialog.htm",window,"status:false;dialogWidth:300px;dialogHeight:300px");}function fnUpdate(){ oName.innerText = sUserName;}</SCRIPT>
7 </HEAD>
8 <BODY>
9 <P>
10 原始值:
11 <SPAN ID="oName" STYLE="color:red;font-size:24">Hello</SPAN>
12 </P>
13 <INPUT TYPE="button" VALUE="弹出对话框" onclick="fnCallDialog()">
14 </BODY>
15 </HTML>
16
17 myDialog.htm
18
19 <HTML>
20 <HEAD>
21 <TITLE>myDialog.htm</TITLE>
22 <SCRIPT>
23 function fnGetInfo() {
24 var sData = dialogArguments;
25 sData.sUserName = oEnterName.value;
26 sData.fnUpdate();
27 }
28 function fnCancel() {
29 var sData = dialogArguments;
30 sData.sUserName = "Joan";
31 sData.fnUpdate();
32 }
33 </SCRIPT>
34 </HEAD>
35 <BODY>
36 <LABEL FOR="oEnterName" ACCESSKEY="f">
37 输入名称:
38 </LABEL>
39 <INPUT ID=oEnterName>
40 <BR>
41 <BR>
42 <INPUT VALUE="应用" TYPE=button onclick="fnGetInfo();">
43 <INPUT VALUE="确定" TYPE=button onclick="fnGetInfo();window.close();">
44 <INPUT VALUE="取消" TYPE=button onclick="fnCancel();window.close();">
45 </BODY>
46 </HTML>
相在文章:
window.dialogArguments 是什么