iframe 去除邊框和自適應高度
阿新 • • 發佈:2019-02-06
因為做專案經常要用到頁面鑲嵌,每次都忘記一些細節問題,特地寫下來以便查閱,很久以前是網上搜到一些前輩的,但是時間太久忘記是哪位了,沒辦法給具體連結。
以下是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>