iframe高度自适应及多浏览器兼容
2012-09-14 23:32
471 查看
/* iframe高度自适应,多浏览器兼容。在ie6,7,8,firefox8.0.1,chorme15.0.874.121中均可行 使用方法: 在iframe的src页面body的onload事件中加入自适应高度函数onload="computeHeight2();"即可。 在computeHeight2中iframe的id写死为sonFrame,你在使用时需要对照自己iframe的id进行相应更改 方法原理: 1 记录上次iframe被设置的高度 2 计算iframe.contentWindow.document.body.scrollHeight 和iframe.contentWindow.document.documentElement.scrollHeight 的值 3 取上述两者的最大值 */ function computeHeight2() { try { var iframe = window.parent.document.getElementById("sonFrame"); //sonFrame是主页中iframe的id iframe.height = 0; //这一行尤为重要 var preHeight = iframe.height; var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var maxheight = Math.max(bHeight, dHeight); iframe.height = maxheight; /* alert("preHeight:" + preHeight + "\n" + "body.scrollHeight:" + bHeight + "\n" + ".documentElement.scrollHeight:" + dHeight + "\n" + "maxHeight:" + maxheight + "\n" + "minheight:" + minheight + "\n" + "now height:" + iframe.height ); */ } catch (ex) { } }
转自: http://blog.csdn.net/wangdonghao137/article/details/7036975
相关文章推荐
- iframe自适应高度(兼容多种浏览器)
- iframe显示高度自适应兼容多浏览器
- jquery兼容各种浏览器的iframe自适应高度的脚本
- JavaScript设置IFrame高度自适应(兼容多浏览器)
- iframe自适应高度(兼容多种浏览器)
- 兼容主流浏览器的iframe自适应高度js脚本
- jquery iframe自适应高度代码(浏览器兼容)
- Iframe自适应高度兼容ie,firefox多浏览器
- JavaScript设置IFrame高度自适应(兼容多浏览器)
- iframe高度宽度自适应兼容所有浏览器
- 基于jquery的兼容各种浏览器的iframe自适应高度的脚本
- 兼容多浏览器的iframe高度自适应问题
- 兼容多浏览器的iframe自适应高度(ie8 、谷歌浏览器4.0和 firefox3.5.3)
- iframe自适应高度(兼容多种浏览器)
- 沫沫金;;最新Iframe全浏览器兼容自适应高度解决方案
- Iframe的高度自适应且兼容谷歌,火狐,IE和360等主流浏览器
- 【开发过程问题汇总系列】【iframe自适应高度】兼容 FireFox和IE内核的浏览器
- 兼容主流浏览器的 iframe 自适应高度(很实用)
- 兼容主流浏览器的iframe自适应高度js脚本