子父視窗之間的操作之小例子
來源:互聯網
上載者:User
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