js 调用父窗口的方法

opener.show();

 

父窗体需要顶一个show() 方法

父面页代码:

 

[html][/html] view plaincopy

  1. <!DOCTYPE HTML PUBLIC “-//IETF//DTD LEVEL1//EN”>
  2. <html>
  3.   <head>
  4.     <title>html.html</title>
  5.     <meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
  6.     <meta http-equiv=”description” content=”this is my page”>
  7.     <meta http-equiv=”content-type” content=”text/html; charset=UTF-8″>
  8.     <!–<link rel=”stylesheet” type=”text/css” href=”./styles.css”>–>
  9.   </head>
  10.   <body>
  11.         <div>
  12.             <button id=”btn”>open new page</button>
  13.         </div>
  14.         <script>
  15.             window.onload=function(){
  16.                 var btn = document.getElementById(“btn”);
  17.                 btn.onclick = openPage;
  18.                 function openPage(){
  19.                     try {
  20.                         window.open(‘newpage.html’);
  21.                     }catch(e){
  22.                         alert(e);
  23.                     }
  24.                     //alert(“ok”);
  25.                 }
  26.             }
  27.             function show(){
  28.                     document.title=new Date();
  29.                 }
  30.         </script>
  31.   </body>
  32. </html>

newpage.html 代码 需要打开的页面

 

 

[html][/html] view plaincopy

  1. <!DOCTYPE HTML PUBLIC “-//IETF//DTD LEVEL1//EN”>
  2. <html>
  3.   <head>
  4.     <title>newpage.html</title>
  5.     <meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
  6.     <meta http-equiv=”description” content=”this is my page”>
  7.     <meta http-equiv=”content-type” content=”text/html; charset=UTF-8″>
  8.     <!–<link rel=”stylesheet” type=”text/css” href=”./styles.css”>–>
  9.   </head>
  10.   <body>
  11.     <button id=”btn” onclick=”fun()”>单击</button>
  12.     <script>
  13.     function fun(){
  14.         opener.show();
  15.     }
  16.     </script>
  17.   </body>
  18. </html>

标签