iframe父与子之间控制实例

本文探讨了HTML页面框架的交互与数据传递机制,包括使用JavaScript实现的跨域通信方法,通过实例展示了如何在不同页面间进行数据共享。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

main.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>New Document</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
    function fun() {
    	window.frames["left"].document.getElementById("ttt").value ="222222";
	}
</script>
</head>
<body>
<frameset rows="50%,50%" frameborder="yes">
	<Iframe name="left" id="left" src="left.html" scrolling="auto"
		frameborder="100"></iframe>
	<Iframe name="right" id="right" src="right.html" scrolling="auto"
		frameborder="100"></iframe>
</frameset>
<input type="text" id="bbb" />
<input type="button" onclick="fun()" value="请调用" />
</body>
</html>

left.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>New Document</title>
<mate name="Generator" content="EditPlus" />
<mate name="Author" content="" />
<mate name="Keywords" content="" />
<mate name="Description" content="" />
<script type="text/javascript">
	function fun() {
		window.parent.document.all('bbb').value = "bbbb";
		var right = window.parent.frames["right"];
		right.document.getElementById("aaa").value = "ccccddd";
		right.aaaaa("left调用right的js");
	}
	function init() {
		alert("main调用left的js");
	}
</script>
</head>
<body onload="init()">
	<table>
		<tr>
			<td></td>
			<td><input type="button" onclick="fun()" value="调用"/> <input type="text"
				id="ttt" /></td>
		</tr>
	</table>
</body>
</html>

right.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>New Document</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
    function aaaaa(aaa) {
		alert("aaa");
	}
</script>
</head>
<body>
	<table>
		<tr>
			<td><input type="text" id="aaa" /></td>
		</tr>
	</table>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值