IFrame自适应高度
2011-11-07 12:55
155 查看
想必很多做web开发的人都遇到过iframe内容有滚动条情况,解决方案也是一搜一大堆。自己在遇到一个高人的方案后,稍微做了下调整,支持IE6、IE8、Chrome、Firefox和Opera,感觉比较理想,在此与各位分享,希望共同进步。
内容不多,也不复杂,不做过多说明。前提是需要需要jquery库,在iframe的onload事件中指定调用该函数即可。
内容不多,也不复杂,不做过多说明。前提是需要需要jquery库,在iframe的onload事件中指定调用该函数即可。
function autoHeight(iframe) { var bHeight; var dHeight; var zeroHeight = 10; var initHeight = 450; if($.browser.msie){ bHeight = iframe.contentWindow.document.body.scrollHeight; iframe.height = zeroHeight; dHeight = iframe.contentWindow.document.documentElement.scrollHeight; } else if($.browser.mozilla || $.browser.opera){ dHeight = iframe.contentWindow.document.documentElement.scrollHeight; iframe.height = zeroHeight; bHeight = iframe.contentWindow.document.body.scrollHeight; } else if($.browser.webkit){ iframe.height = zeroHeight; dHeight = iframe.contentWindow.document.documentElement.scrollHeight; bHeight = iframe.contentWindow.document.body.scrollHeight; } else { iframe.height = zeroHeight; dHeight = iframe.contentWindow.document.documentElement.scrollHeight; bHeight = iframe.contentWindow.document.body.scrollHeight; } var height = bHeight > dHeight ? bHeight : dHeight; //alert(bHeight + ":" + dHeight + "=>" + height); if(height < initHeight){ height = initHeight; } iframe.height = height; }
相关文章推荐
- Iframe用法的详细讲解(属性、透明、自适应高度)和html中滚动条属性设置
- iframe自适应高度
- 框架iframe自适应高度
- iframe 自适应高度,更改内容时iframe高度怎么根据新的内容高度自动改变
- iframe框架高度自适应
- iframe自适应高度
- 【转载】iframe自适应高度详解(转帖)
- 再谈iframe自适应高度
- 同域及跨域下iframe高度自适应(兼容IE/FF/OP/Chrome)
- 再谈iframe自适应高度
- 再谈iframe自适应高度
- iframe高度自适应,全屏,大小伸缩,有滚动条
- Iframe高度自适应(兼容IE/Firefox、同域/跨域)
- Iframe 高度自适应(兼容IE/Firefox、同域/跨域)
- iframe 自适应高度
- iframe自适应高度
- 设置HTML中的Iframe框架自适应高度
- iframe加载后自适应高度
- iframe自适应高度
- iframe高度自适应