iframe无边框度自适应

吴wuwu

关注

阅读 104

2023-03-11

iframe无边框度自适应

<iframe src="http://www.httple.net" style="width:100%;height:1100px" name="iframe_a"  frameborder="no" id="ifr" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"></iframe>    
<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>

精彩评论(0)

0 0 举报