对iFrame 自适应高度的解决办法
2012-03-08 14:54
260 查看
这两天写了几个页面,布局的时候用到了Iframe,在IE下调试一切正常,不经意间用Firefox打开来看了一下,那效果真是可以用惨不忍睹来形容,Firefox居然不认识高度为100%.
<iframe src="Index.jsp" name="mainFrame" id="mainFrame" frameborder="0" scrolling="auto" style="width:817px;height:100%;"></iframe>
乍一看也没什么不妥,可是火狐就是不认这个height:100%,上Google搜索了一下,找到段脚本,改了改,就解决这个问题了.
思路:首先判断浏览器是IE还是火狐,然后专门针对火狐做单独的样式处理.
<script type="text/javascript">
function resizeIframe(obj) {
var Iframe = document.getElementById(obj);
if (Iframe){
if (Iframe.contentDocument){//ff
Iframe.style.height = Iframe.contentDocument.body.scrollHeight +60+'px';
}
else if(Iframe.document && Iframe.document.body.scrollHeight){//ie
Iframe.style.height = mainFrame.document.body.scrollHeight + 60 + 'px';
}
}
}
</script>
在Iframe加载的时候就调用这个函数
<iframe src="index.jsp" name="mainFrame" id="mainFrame" onload="resizeIframe('mainFrame')" frameborder="0" scrolling="auto" style="width:817px;height:100%;"></iframe>
<iframe src="Index.jsp" name="mainFrame" id="mainFrame" frameborder="0" scrolling="auto" style="width:817px;height:100%;"></iframe>
乍一看也没什么不妥,可是火狐就是不认这个height:100%,上Google搜索了一下,找到段脚本,改了改,就解决这个问题了.
思路:首先判断浏览器是IE还是火狐,然后专门针对火狐做单独的样式处理.
<script type="text/javascript">
function resizeIframe(obj) {
var Iframe = document.getElementById(obj);
if (Iframe){
if (Iframe.contentDocument){//ff
Iframe.style.height = Iframe.contentDocument.body.scrollHeight +60+'px';
}
else if(Iframe.document && Iframe.document.body.scrollHeight){//ie
Iframe.style.height = mainFrame.document.body.scrollHeight + 60 + 'px';
}
}
}
</script>
在Iframe加载的时候就调用这个函数
<iframe src="index.jsp" name="mainFrame" id="mainFrame" onload="resizeIframe('mainFrame')" frameborder="0" scrolling="auto" style="width:817px;height:100%;"></iframe>
相关文章推荐
- asp.net页面中Menu控件下拉菜单被frame挡住和iframe自适应高度的解决办法
- asp.net页面中Menu控件下拉菜单被frame挡住和iframe自适应高度的解决办法
- 【原】 iFrame 自适应高度解决不了的问题所在和解决办法
- Iframe自适应页面高度问题的最简单最适用的解决办法
- iframe自适应高度,多层嵌套iframe自适应高度的解决方法
- 转:困扰许久的问题 - div自适应内容高度且有最小高度的解决办法
- IFRAME自适应高度的解决方法
- Excel编程中关于跨列单元格的自适应高度的解决办法
- 解决跨域iframe自适应高度(转自:http://www.lzlu.com/blog/?p=692)
- 真正解决iframe自适应高度
- ul li浮动后高度不能自适应解决办法
- jquery ajax应用中iframe自适应高度问题解决方法
- iframe 跨域高度自适应的解决办法
- 自适应高度div内嵌iframe高度被撑开问题解决
- IOS 7.0以后的UILabel自适应高度解决办法.
- iframe 自适应高度问题解决方法
- 解决iframe自适应高度问题
- div高度不自适应,溢出的一种解决办法
- jQuery解决iframe高度自适应代码
- 解决iframe跨域高度自适应问题