您的位置:首页 > 其它

<iframe>标签自适应高度和宽度

2016-12-29 10:00 225 查看
js解决iframe标签自适应高度和宽度:

<iframe src="index.html" id="iframepage"  frameborder="0" scrolling="no" marginheight="0" marginwidth="0" onLoad="iFrameHeight()"></iframe>

<script type="text/javascript" language="javascript">   

function iFrameHeight() {   

var ifm= document.getElementById("iframepage");   

var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;   

if(ifm != null && subWeb != null) {

   ifm.height = subWeb.body.scrollHeight;

   ifm.width = subWeb.body.scrollWidth;

}   

}   
</script>

注:iframe高度不能默认设置为100%或者auto。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iframe