父框架
<body></body>
<script type="text/javascript">
document.domain = '100bt.com';
var ifr = document.createElement('iframe');
ifr.src = 'http://www.100bt.com/b.html';
ifr.style.display = 'none';
document.body.appendChild(ifr);
function alertA(str){
alert(str);
}
ifr.onload = function(){
var doc = ifr.contentDocument || ifr.contentWindow.document;//获取子框架b的document
ct = ifr.contentWindow;//获取子框架的window,可用作跨域使用
// 在这里操纵b.html alert(doc.getElementsByTagName("h1")[0].childNodes[0].nodeValue);//使用子框架b的document内容
ct.log(doc);//使用子框架b的方法
};
</script>
子框架
<h1>xxd</h1>
<script type="text/javascript">document.domain = '100bt.com';
function log(str){
console.log(str);
}
var p = window.parent //获取父框架a的window对象
p.alertA("paere") //使用父框架的方法
</script>
页面打开效果(大概也能拿猜出来):
子框架使用父框架a的脚本弹出内容
弹出子框架b的h1内容
父框架a打印子框架的内容