兼容各浏览器的iframe方法

 

方法一:(推荐1)

<iframe id="frame_content" src="/Home/[email protected]" scrolling="no" frameborder="0" height="100%" width="82%"></iframe>
<script type="text/javascript">
$("#frame_content").load(function () {
$(this).height($(this).contents().height());
})
</script>

 

方法二:

<iframe id="frame_content" src="/Home/[email protected]" scrolling="no" frameborder="0" onload="this.height=100" width="82%"></iframe>
<script type="text/javascript">
function reinitIframe() {
var iframe = document.getElementById("frame_content");
try {
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
} catch (ex) { }
}
window.setInterval("reinitIframe()", 200);
</script>

你可能感兴趣的:(iframe)