比如 'http://hebei.hebnews.cn/3.html' 嵌入了 'http://bbs.hebnews.cn/4.html',这种跨子域的页面
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>3.html</title>
<script type="text/javascript">
document.domain = 'hebnews.cn'
</script>
</head>
<body>
<iframe id="ifr" src="http://bbs.hebnews.cn/4.html" frameborder="0" width="100%"></iframe>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>4.html</title>
<script type="text/javascript">
document.domain = 'hebnews.cn'
</script>
</head>
<body>
<p>这是一个ifrmae,嵌入在http://hebei.hebnews.cn/3.html里 </p>
<p>根据自身内容调整高度</p>
<script>
// 计算页面的实际高度,iframe自适应会用到
function calcPageHeight(doc) {
var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight)
var height = Math.max(cHeight, sHeight)
return height
}
window.onload = function() {
var height = calcPageHeight(document)
parent.document.getElementById('ifr').style.height = height + 'px'
}
</script>
</body>
</html>
除非注明,均为湛蓝天空原创,转载请注明本文网址:http://skyhome.cn/js/500.html