父窗口
1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title>window object</title> 6 7 <script type="text/javascript"> 8 9 10 </script> 11 12 </head> 13 <body> 14 <div onclick="window.open('bless.html','aa','width=400,height=500')">祝福语</div> 15 <div id="m"></div> 16 </body> 17 </html>
子窗口
1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 7 <script type="text/javascript"> 8 function mess(){ 9 //获取祝福语 10 var message = document.getElementById("blessMes").value; 11 //获取父类窗口 12 var p = window.opener; 13 //获取父类窗口中的id为bless的div 14 var pd = p.document.getElementById("m"); 15 //设置pd的值 16 pd.innerHTML = message; 17 //关闭当前窗口 18 window.close(); 19 } 20 21 22 </script> 23 24 </head> 25 <body> 26 <input id="blessMes" type="text" > 27 <input type="button" value="送上祝福" onclick="mess()"> 28 </body> 29 </html>