`

Javascript window 对象+ 父子窗口之间相互操作

 
阅读更多
例1 用window.open()打开的父子窗口
test.html
<html>
<head>
</head>
<body>
<input type="button" onclick="show(this)" value="blue"/>
<input type="button" onclick="show(this)" value="green"/>
<input type="button" onclick="show(this)" value="red"/>
<script>
var subwin = window.open('sub.html','_blank','top=50,left=50,height=50,width=50');
function show(obj){
	subwin.document.bgColor=obj.value;
}
function test(){
	window.document.title='4444';
}
</script>
</body>
</html>



sub.html
<html>
<head>
<style>

</style>
</head>
<body>
<input type="button" onclick="show(this)" value="blue"/>
<input type="button" onclick="show(this)" value="green"/>
<input type="button" onclick="show(this)" value="red"/>
<input type="button" onclick="opener.test()" value="test"/>
<script>
function show(obj){
	opener.document.bgColor=obj.value;
}
</script>
</body>
</html>




例2 用frame打开的父子窗口
test.html
<frameset rows="100,*">
	<frame name="top" src="">
	<frameset cols="150,*">
		<frame name="menu" src="menu.html">
		<frame name="main" src="">
	</frameset>
</frameset>


menu.html
<input type="button" onclick="window.parent.frames[0].document.bgColor='green'" value="changetop"/>
<input type="button" onclick="window.document.bgColor='red'" value="changeself"/>
<input type="button" onclick="window.top.main.document.bgColor='blue'" value="changemain"/>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics