让iframe简单有效自适应高度
2011-08-09 15:36
190 查看
一种简单有效自适应高度的iframe
<iframe src="show.htm" id="show" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" width="100%" onload="this.height=0;var fdh=(this.Document?this.Document.body.scrollHeight:this.contentDocument.body.offsetHeight);this.height=(fdh>7?fdh:7)"></iframe>
注:onload字段中的数值“7”为Iframe最低高度值,可自定义!
另外这个同时支持IE&Firefox:)
PS:如果内页的CSS设置了BODY的MARGIN属性,IFRAME自适应的高度不会把margin-top和margin-bottom的值加到里面,所以最后这地方this.height=(fdh>450?fdh:400)得改成
this.height=(fdh>450?fdh+margin-top的高度+margin-bottom的高度:400)
比如说
this.height=(fdh>450?fdh+20+15:400) //尚未测试
相关文章推荐
- 两段超简单jquery代码解决iframe自适应高度问题(不用判断浏览器高度)
- Iframe自适应页面高度问题的最简单最适用的解决办法
- 两段超简单jquery代码解决iframe自适应高度问题(不用判断浏览器高度)
- 简单的iframe自适应高度和宽度
- 实现iFrame自适应高度,原来非常简单!
- iframe高度自适应的有效办法
- 一个简单的高度自适应iframe
- iframe 自适应高度最简单代码
- 最简单的方式让iframe根据内容显示高度即自适应高度
- iframe自适应高度(简单经典)兼容ie6-ie9 ,firefox,opera,chrome
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
- iframe 自适应高度
- iframe 跨域自适应高度
- iframe自适应高度
- iframe自适应高度
- CSS完美实现iframe高度自适应(支持跨域)
- cell自适应高度的简单写法
- iframe高度自适应
- iframe 自适应高度
- iframe自适应高度