站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题子父窗口之间的操作之小例子

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

摘要: 子父窗口之间的操作之小例子


用window.openr打开的子父窗口之间的操作跟框架的是不一样的,子窗口和父窗口之间有opener来联系。而源窗口要访问子窗口要通过其句柄来操作。以下小例子希望能帮助新手更了解他们的操作。

test.htm  


<head>



子父窗口的操作
</head>
<body>
<script>
var win=null;
function op(){
win=window.open("about:blank","win","width=200,height=200");
win.document.write("<input type='button' value='关闭父窗口' onclick='window.opener.opener=null;window.opener.close()'>");
win.document.write("<input type='button' value='刷新你窗口' onclick='window.opener.location.reload()'>");
}
</script>
<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('还没有打开窗口或者已关闭')};">
</body>

运行效果如下:

<script> var win=null; function op(){ win=window.open("about:blank","win","width=200,height=200"); win.document.write("<input type='button' value='关闭父窗口' onclick='window.opener.opener=null;window.opener.close()'>"); win.document.write("<input type='button' value='刷新你窗口' onclick='window.opener.location.reload()'>"); } </script> <input onclick=op() type=button value=打开窗口><input onclick="if(win&&win.open&&!win.closed){win.resizeTo(0,0);win.moveTo(0,window.screen.width);}else alert('还没有打开窗口或已经关闭')" type=button value=最小化><input onclick="if(win&&win.open&&!win.closed){win.moveTo(-4,-4);win.resizeTo(screen.availWidth+8,screen.availHeight+8);}else alert('还没有打开窗口或已经关闭');" type=button value=最大化><input onclick="if(win&&win.open&&!win.closed){win.opener=null;win.close()}else alert('还没有打开窗口或已关闭')" type=button value=关闭子窗口><input onclick="if(win&&win.open&&!win.closed){win.location.reload();win.focus()}else alert('窗口还没有打开或已关闭')" type=button value=刷新子窗口><input onclick="if(win&&win.open&&!win.closed){alert(win.document.body.clientWidth+'*'+win.document.body.clientHeight);win.focus();}else{alert('还没有打开窗口或者已关闭')};" type=button value=看子窗口的大小>

以上只供参考,有错请纠正,谢谢!

</td> </tr> <tr> <td vAlign=top align=left height="100%">
↑返回目录
前一篇: 如何在页面显示来访者分辨率,浏览器(js)
后一篇: HTML在线编辑器Word XP