iframe 自适应高度js

来源:互联网 发布:室内设计网站 知乎 编辑:程序博客网 时间:2024/05/29 16:14

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()需改

0 0
原创粉丝点击