iframe高度动态自适应实例页面

展示

回到相关文章 >>

代码

HTML代码:
<iframe id="testIframe" frameborder="0" scrolling="no" src="iframe-page-fresh-home.html" width="100%" height="90"></iframe>
            
JS代码:
//高度自适应
var iframe = document.getElementById("testIframe");
var iframeHeight = function() {    
    var hash = window.location.hash.slice(1), h;
    if (hash && /height=/.test(hash)) {
        h = hash.replace("height=", "");
        iframe.height = h;
    }
    setTimeout(iframeHeight, 100);
};
iframeHeight();