<iframe width="300" id="iframetestid" frameborder="0" scrolling="no" src="test.php" οnlοad="setTimeout(function(){reSetIframe('iframetestid');},200);" ></iframe>
function reSetIframe(iframeid){var iframe = document.getElementById(iframeid);var height = 500;try{var bHeight = iframe.contentWindow.document.body.scrollHeight;var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;height = Math.max(bHeight, dHeight);iframe.height = height;}catch (ex){height = Math.max(bHeight, dHeight);iframe.height = height;}}
这个适应于各种浏览器,从ie6 7 8 9 一直到 ff,chrome
调试了很久的ie6一直取不到值,最后发现原因是要设置函数reSetIframe定时执行,直接执行虽然用onload还是取不到,要延迟一会ie6才能得到height值。