.iframe的使用A域中有parent.html,B域中有child.html.B域中的服务器要监听所有B域下所有child.html,并且两个域之间要交换数据.那么在A域中嵌入iframe
如: parent.html
<iframe hieght=0 width=0 id="child" name="child" src="访问路径+child.html"></iframe>
document.domain =IP //A域的IP或域名(去掉www)
函数function thisparent(){
alert("This is parent");
}
document.getElementById("child").contentWindow.thischild();
child.html
document.domain=IP//A域的IP或域名(去掉www)
function thischild(){
alert("This is child");
}
parent.thispatent();
如: parent.html
<iframe hieght=0 width=0 id="child" name="child" src="访问路径+child.html"></iframe>
document.domain =IP //A域的IP或域名(去掉www)
函数function thisparent(){
alert("This is parent");
}
document.getElementById("child").contentWindow.thischild();
child.html
document.domain=IP//A域的IP或域名(去掉www)
function thischild(){
alert("This is child");
}
parent.thispatent();
本文介绍了一种通过设置document.domain实现跨域访问的方法,并演示了如何利用iframe在不同域间进行数据交换。具体实现包括在父页面中引用子页面,并在两者之间互相调用函数。
1534

被折叠的 条评论
为什么被折叠?



