showModalDialog使用例子,父窗口向子窗口传递值,子窗口设置父窗口的值,子窗口关闭的时候返回值到父窗口

 (一)showModalDialog使用例子,父窗口向子窗口传递值,子窗口设置父窗口的值,子窗口关闭的时候返回值到父窗口.

farther.html
---------------------------

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3.     <HEAD>
  4.         <TITLE>New Document </TITLE>
  5.         <META content="EditPlus" name="Generator">
  6.         <META content="" name="Author">
  7.         <META content="" name="Keywords">
  8.         <META content="" name="Description">
  9.         <script language="javascript"
  10.         <!-- 
  11.         function openChild(){
  12.         var k = window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px"); 
  13.         if(k != null
  14.         document.getElementById("txt11").value = k; 
  15.         } 
  16.         //--> 
  17.         </script>
  18.     </HEAD>
  19.     <BODY>
  20.         <FONT face="宋体"></FONT>
  21.         <br>
  22.         传递到父窗口的值:<input id="txt9" type="text" value="3333333333333" name="txt9"><br>
  23.         返回的值:<input id="txt11" type="text" name="txt11"><br>
  24.         子窗口设置的值:<input id="txt10" type="text" name="txt10"><br>
  25.         <input id="Button1" οnclick="openChild()" type="button" value="openChild" name="Button1">
  26.     </BODY>
  27. </HTML>

child.html
---------------------------

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3.     <HEAD>
  4.         <TITLE>New Document </TITLE>
  5.         <META content="EditPlus" name="Generator">
  6.         <META content="" name="Author">
  7.         <META content="" name="Keywords">
  8.         <META content="" name="Description">
  9.         <meta http-equiv="Expires" content="0">
  10.         <meta http-equiv="Cache-Control" content="no-cache">
  11.         <meta http-equiv="Pragma" content="no-cache">
  12.     </HEAD>
  13.     <BODY>
  14.         <FONT face="宋体"></FONT>
  15.         <br>
  16.         父窗口传递来的值:<input id="txt0" type="text" name="txt0"><br>
  17.         输入要设置父窗口的值:<input id="txt1" type="text" name="txt1"><input id="Button1" οnclick="setFather()" type="button" value="设置父窗口的值" name="Button1"><br>
  18.         输入返回的值:<input id="txt2" type="text" name="txt2"><input id="Button2" οnclick="retrunValue()" type="button" value="关闭切返回值" name="Button2">
  19.         <input id="Button3" οnclick="" type="button" value="关闭刷新父窗口" name="Button3">
  20.         <script language="javascript"
  21.         <!-- 
  22.         var k=window.dialogArguments; 
  23.         //获得父窗口传递来的值 
  24.         if(k!=null
  25.         { 
  26.         document.getElementById("txt0").value = k.document.getElementById("txt9").value; 
  27.         } 
  28.         //设置父窗口的值 
  29.         function setFather() 
  30.         { 
  31.         k.document.getElementById("txt10").value = document.getElementById("txt1").value 
  32.         } 
  33.         //设置返回到父窗口的值 
  34.         function retrunValue() 
  35.         { 
  36.         var s = document.getElementById("txt2").value; 
  37.         window.returnValue=s; 
  38.         window.close(); 
  39.         } 
  40.         //--> 
  41.         </script>
  42.     </BODY>
  43. </HTML>

----------------------------
说明:
由于showModalDialog缓存严重,下面是在子窗口取消客户端缓存的设置.也可以在服务器端取消缓存,参考:
http://adandelion.cnblogs.com/articles/252137.html
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

 


(二)下面是关闭刷新父窗口的例子

farther.html
---------------------------

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3.     <HEAD>
  4.         <TITLE>New Document </TITLE>
  5.         <META NAME="Generator" CONTENT="EditPlus">
  6.         <META NAME="Author" CONTENT="">
  7.         <META NAME="Keywords" CONTENT="">
  8.         <META NAME="Description" CONTENT="">
  9.         <script language="javascript"
  10.         <!-- 
  11.         function openChild() 
  12.         { 
  13.         var k = window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px"); 
  14.         if(k == 1)//判断是否刷新 
  15.         { 
  16.         alert('刷新'); 
  17.         window.location.reload(); 
  18.         } 
  19.         } 
  20.         //--> 
  21.         </script>
  22.     </HEAD>
  23.     <BODY>
  24.         <br>
  25.         传递到父窗口的值:<input id="txt9" type="text" value="3333333333333" NAME="txt9"><br>
  26.         <input type="button" value="openChild" οnclick="openChild()" ID="Button1" NAME="Button1">
  27.     </BODY>
  28. </HTML>

child.html
----------------------

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3.     <HEAD>
  4.         <TITLE>New Document </TITLE>
  5.         <META content="EditPlus" name="Generator">
  6.         <META content="" name="Author">
  7.         <META content="" name="Keywords">
  8.         <META content="" name="Description">
  9.         <meta http-equiv="Expires" content="0">
  10.         <meta http-equiv="Cache-Control" content="no-cache">
  11.         <meta http-equiv="Pragma" content="no-cache">
  12.     </HEAD>
  13.     <BODY>
  14.         <FONT face="宋体"></FONT>
  15.         <br>
  16.         父窗口传递来的值:<input id="txt0" type="text" name="txt0"><br>
  17.         <input id="Button1" οnclick="winClose(1)" type="button" value="关闭刷新父窗口" name="Button1">
  18.         <input id="Button2" οnclick="winClose(0)" type="button" value="关闭不刷新父窗口" name="Button2">
  19.         <script language="javascript"
  20.         <!-- 
  21.         var k=window.dialogArguments; 
  22.         //获得父窗口传递来的值 
  23.         if(k!=null
  24.         { 
  25.         document.getElementById("txt0").value = k.document.getElementById("txt9").value; 
  26.         } 
  27.         //关闭窗口返回是否刷新的参数. 
  28.         function winClose(isRefrash) 
  29.         { 
  30.         window.returnValue=isRefrash; 
  31.         window.close(); 
  32.         } 
  33.         //--> 
  34.         </script>
  35.     </BODY>
  36. </HTML>

--------------------------
说明
1.下面是取消客户端缓存的:
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
也可以在服务器端取消缓存,参考:
http://adandelion.cnblogs.com/articles/252137.html

2.向父窗口传递阐述在ASP.NET中也可以是用aaa.aspx?id=1的方式传递.

3.不刷新父窗口的话在父窗口中直接这样一来设置可以.
<script>
window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");
</script>
4.在子窗口中若要提交页面的话要加入:,这样就不会打开新窗口了.
<head>
<base target="_self">
</HEAD>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值