iframe子页互相传值
Posted on : 03-08-2009 | By : kim | In : 开发
0
由于子页1无法直接访问子页2,所以只能通过给父页传参数,再让父页给子页2传值。
父页:
<script type=”text/javascript”>
function insert(sValue)
{
alert(sValue);
document.getElementById(“if3″).contentWindow.document.getElementsByTagName(“body”)[0].innerHTML = sValue;
}
</script>
<body>
这里是父页
<iframe id=”if2″ src=”22.html”></iframe>
<iframe id=”if3″ src=”33.html”></iframe>
</body>
子页1:
<script type=”text/javascript”>
function pass()
{
var sValue = document.getElementById(“txt”).value;
parent.insert(sValue)
}
</script>
<body>
这里是子页1
<input type=”text” id=”txt” value=”要传什么东西过去呢?” />
<input type=”button” onclick=”pass()” value=”点击” />
</body>
子页2:
<body>
这里是子页2
</body>