iframe高度自适应
var adjustIframe = function(id, end) { var iframe = document.getElementById(id), time = 0, end = end || 30, intervalID if (iframe) { function callback() { time = time + 1 if (time == end) { clearInterval(intervalID) } var idoc = iframe.contentWindow && iframe.contentWindow.document || iframe.contentDocument; var iheight = Math.max(idoc.body.scrollHeight, idoc.documentElement.scrollHeight); //取得其高 iframe.style.height = iheight + "px"; } intervalID = setInterval(callback, 50) } }
<iframe id="js_sub_web" width="80%" frameborder="0" scrolling="no" allowTransparency="true" src="http://www.cnblogs.com/rubylouvre/archive/2009/09/15/1566722.html"> </iframe>
使用方法:
window.onload = function(){ adjustIframe("js_sub_web"); }
注意,本脚本只能处理同域的iframe高度
机器瞎学/数据掩埋/模式混淆/人工智障/深度遗忘/神经掉线/计算机幻觉/专注单身二十五年