您的位置:首页 > 其它

iframe 高度自适应

2009-09-29 19:27 204 查看
根据iframe 内容的滚动条高度自动调整iframe 的高度。

1、iframe 的设置:

<iframe width="100%" id="autoHeightIframe"

onload="Javascrīpt:setIframeHeight(this)" frameborder="0" scrolling="no">

</iframe>

2、JavaScript 脚本设置:

<script>

//自动调整 iframe 高度

function setIframeHeight(iobj) {

var win = iobj;

if (document.getElementById("autoHeightIframe")) {

if(win && !window.opera) {

if (win.contentDocument && win.contentDocument.body.offsetHeight) {

win.height = win.contentDocument.body.offsetHeight;

}else if (win.Document && win.Document.body.scrollHeight) {

win.height = win.Document.body.scrollHeight;

}

}

}

}

</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: