您的位置:首页 > 大数据 > 人工智能

document.domain 跨域实现

2016-05-26 14:03 561 查看
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<title>document.domains</title>
</head>
<body>
<p>我是www页面</p>
<iframe src="http://test.mzk.com/domains.html" id='ifm'></iframe>
</body>
<script type="text/javascript">
document.domain='mzk.com';
function alt(){

}
var ifm=document.getElementById('ifm');
ifm.onload = function(){
var doc = ifm.contentDocument || ifm.contentWindow.document;
// 在这里操纵b.html
doc.getElementById('btn').onclick=function(){
alert('我是www页面');
}
};
</script>
</html>


上面是http://www.mzk.com/damains.html;
http://test.mzk.com/domains.html页面是:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<title>document.domains</title>
</head>
<body>
<input type="button" class="btn" id="btn" value="按钮" >
</body>
<script type="text/javascript">
document.domain='mzk.com';
</script>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: