您的位置:首页 > Web前端 > JavaScript

iframe 自适应高度js

2015-10-19 10:57 288 查看
iframe 自适应高度

<script>
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;
}
var ifr = document.getElementById('iframepage');
ifr.onload = function() {
var iDoc = ifr.contentDocument || ifr.document;
var height = calcPageHeight(iDoc);
ifr.style.height = height + 'px';
}
</script>

放在body最后,document.getElementById()需改
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: