JavaScript -- Opener

时间:2021-09-12 20:11:44

-----028-Window-Opener.html-----

 <!DOCTYPE html>
 <html>
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     <title>标题</title>
 </head>
 <body>
 <script type="text/javascript">
     function getTime()
     {
         if(newWin.closed)
         {
             window.clearInterval(intervalID);
             window.alert("窗口打开了" + t + "秒");
         }
         else
         {
             t++;
             newWin.opener.document.write("子窗体打开了" + t + "秒");
         }
     }
     function openNew()
     {
         newHtml = "<h4>打开新窗体</h4><center><input type='button', value='关闭'onclick='window.close();'/></center>"
         newWin = window.open("", "新窗口", "height=200, width=200, toolbar=no, menubar=no, status=yes, location=no, top=200, left=200");
         newWin.document.write(newHtml);
         t = 0;
         intervalID = window.setInterval(getTime, 1000);

     }

 </script>
 <input type="button" value="New" onclick="openNew()"/>
 </body>
 </html>

JavaScript -- Opener