System Information

Impossible Is Nothing...

导航

子父窗口之间的操作之小例子

 1 用window.openr打开的子父窗口之间的操作跟框架的是不一样的,子窗口和父窗口之间有opener来联系。而源窗口要访问子窗口要通过其句柄来操作。以下小例子希望能帮助新手更了解他们的操作。
 2 
 3 test.htm  
 4 
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 8 <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
 9 <meta name="ProgId" content="FrontPage.Editor.Document">
10 <title>子父窗口的操作</title>
11 </head>
12 <body>
13 <script>
14 var win=null;
15 function op(){
16 win=window.open("about:blank","win","width=200,height=200");
17 win.document.write("<input type='button' value='关闭父窗口' onclick='window.opener.opener=null;window.opener.close()'>");
18 win.document.write("<input type='button' value='刷新你窗口' onclick='window.opener.location.reload()'>");
19 }
20 </script>
21 <input onclick="op()" value="打开窗口" type="button"><input type="button" value="最小化" onclick="if(win&&win.open&&!win.closed){win.resizeTo(0,0);win.moveTo(0,window.screen.width);}else alert('还没有打开窗口或已经关闭')"><input type="button" value="最大化" onclick="if(win&&win.open&&!win.closed){win.moveTo(-4,-4);win.resizeTo(screen.availWidth+8,screen.availHeight+8);}else alert('还没有打开窗口或已经关闭');"><input type=button value="关闭子窗口" onclick="if(win&&win.open&&!win.closed){win.opener=null;win.close()}else alert('还没有打开窗口或已关闭')"><input type=button value="刷新子窗口" onclick="if(win&&win.open&&!win.closed){win.location.reload();win.focus()}else alert('窗口还没有打开或已关闭')"><input type="button" value="看子窗口的大小" onclick="if(win&&win.open&&!win.closed){alert(win.document.body.clientWidth+'*'+win.document.body.clientHeight);win.focus();}else{alert('还没有打开窗口或者已关闭')};">
22 </body>
23 </html>
24 
25 

posted on 2005-11-17 20:10  SysInfo  阅读(436)  评论(0编辑  收藏  举报