背景:涉及到系统集成的时候,前端我们经常会用到iframe嵌入,但是嵌入的时候经常有不适应的情况,太长或太宽、滚动条等等
解决办法(下面的方法可以做到使嵌入的iframe自适应高度宽度)
1.嵌入iframe,加上onload事件
<iframe id="bi_iframe" src="http://xx.xx.xx.xx/yourServicePath¶1=xxx" onload="adjustIframe();"
frameborder="0" scrolling="auto">
</iframe>
2.添加自适应js
function adjustIframe(){
var ifm= document.getElementById("bi_iframe");
ifm.height=document.documentElement.clientHeight;
ifm.width=document.documentElement.clientWidth;
}
或者:
<div class="contentDiv">
<iframe id="mainFrame" name="mainFrame" class="mainFrame" src=" " frameborder="0" allowtransparency="true" " onload="this.height=mainFrame.document.body.scrollHeight;this.widt
h=document.documentElement.clientWidth" scrolling="auto">
</iframe>
</div>