javascript父子窗口传递数据

在网上找了一些例子 :)

AA.html是主页面,其他的是例子。

1、AA.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>主界面</title>
</head>
<body>
 <form id="getForm">
  回传值:
  <input type="text" id="getData" readOnly>
  <input type="text" id="getData1" readOnly>
 </form>
 <input type="button" value="打开新窗口1" onClick="openWin1()">
 <input type="button" value="打开新窗口2" onClick="openWin2()">
 <input type="button" value="打开新窗口3" onClick="openWin3()">
 <script language="JavaScript">   
  function openWin1(){       
    var srcFile = "BB.html";    //新窗口的文档名称       
    var winFeatures = "dialogHeight:300px; dialogLeft:200px;";       
    var obj = getForm;  //将form作为对象传递给新窗口              
    window.showModalDialog(srcFile, obj, winFeatures);   
  }
  function openWin2(){       
    var srcFile = "CC.html";    //新窗口的文档名称       
    var winFeatures = "dialogHeight:300px; dialogLeft:200px;";       
    var obj = getForm.getData.value;  //将form作为对象传递给新窗口              
    var str=window.showModalDialog(srcFile, obj, winFeatures);   
    if(str!=null)
    getForm.getData.value = str;
  }
  function openWin3(){       
    var srcFile = "DD.html";    //新窗口的文档名称  
    window.open(srcFile,"new",winFeatures);
  }
 </script>
</body>
</html>

2、BB.html  function openWin1()

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新窗口BB</title>
</head>
<base target="_self">
<!--这句话非常重要,只要加上才能保证在弹出窗口中调用服务端代码而不会再弹出一个新窗口-->
<body>
<form id="sendForm">
 请输入资料:
 <input type="text" id="writeData">   
 <input type="text" id="writeData1">
 <input type="button" value="送回父窗口" onClick="send(sendForm.writeData.value,sendForm.writeData1.value);">
</form>
<script language="JavaScript">   
 function send(val,val1){       
  //取得父窗口传过来的对象       
  var myObj = window.dialogArguments;       
  //赋值
  myObj.getData.value = val;
  myObj.getData1.value = val1;
  //关闭窗口       
  window.close();   
 }
</script>
</body>
</html>

3、CC.html  function openWin2()

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新窗口CC</title>
</head>
<base target="_self">
<body>
<form id="sendForm">
 请输入资料:
 <input type="text" id="writeData">   
 <input type="button" value="送回父窗口" onClick="send(sendForm.writeData.value);">
</form>
<script language="JavaScript">   
 function send(val){       
  window.returnValue=val
  window.close();   
 }
</script>
</body>
</html>

4、DD.html  function openWin3()

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新窗口DD</title>
</head>
<body>
<form id="sendForm">
 请输入资料:
 <input type="text" id="writeData">   
 <input type="text" id="writeData1">
 <input type="button" value="送回父窗口" onClick="send(sendForm.writeData.value,sendForm.writeData1.value);">
</form>
<script language="JavaScript">   
 function send(val,val1){       
    opener.getForm.getData.value = val;
    opener.getForm.getData1.value = val1;
  window.close();   
 }
</script>
</body>
</html>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值