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高度
http://www.cnblogs.com/rubylouvre/archive/2011/01/05/1926226.html