因为做项目经常要用到页面镶嵌,每次都忘记一些细节问题,特地写下来以便查阅,很久以前是网上搜到一些前辈的,但是时间太久忘记是哪位了,没办法给具体链接。
以下是js代码:
<script type="text/javascript">
function reinitIframe() {
var iframe = document.getElementById("frame");
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>
以下是html代码:
<iframe src="<%=basePath %>report${wordpath}" id="frame" scrolling="no" frameborder="0" style="overflow: auto; margin: auto; width: 80%;"> </iframe>