iframe
<iframe name="menuFrame" id="menuFrame" onload="reinitIframe()" style="overflow:visible;"
scrolling="no" height="100%" width="100%">
</iframe>
javascript
window.onresize = function () {
reinitIframe();
}
function reinitIframe(){
var iframe = document.getElementById("menuFrame");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.min(bHeight, dHeight);
iframe.height = height+50;
// console.log(iframe.height);
}catch (ex){}
}
// 定时触发
window.setInterval("reinitIframe()", 200);
本文介绍了一种使iframe元素自适应其内容高度的方法,通过使用JavaScript监听窗口大小变化及定时调整iframe高度,确保iframe能根据内部内容自动调整,避免滚动条出现。
852

被折叠的 条评论
为什么被折叠?



