IFrame高度设置
来源:互联网 发布:数据处理软件pen 编辑:程序博客网 时间:2024/05/01 01:16
由于最近想实现网页局部刷新,使用的IFrame,只要给IFrame赋给新的src值,便可以加载不同的页面了。但让人烦恼的问题也随之而来了,那便是如何让IFrame自身的高度随子页面而变化。上网搜了好多方法,发现都不适用。
很多人的方法都是这样的。在IFrame中设置 onload="autoHeight();“
function autoHeight(){
var iframe =document.getElementById("container");
if(iframe.Document){//ie自有属性
iframe.style.height =iframe.Document.documentElement.scrollHeight;
}elseif(iframe.contentDocument){//ie,firefox,chrome,opera,safari
iframe.height =iframe.contentDocument.body.offsetHeight ;
}
}
这种方法在FireFox和Chrome中显示很好,但是在IE中完全不好使,后来才发现,在IE中不能用iframe.Document,得用iframe.contentWindow。
修改之后的代码为:
function autoHeight(){
var iframe = document.getElementById("container");
if(iframe.Document){//ie自有属性
iframe.style.height = iframe.contentWindow.document.body.scrollHeight+20;
}else if(iframe.contentDocument){//ie,firefox,chrome,opera,safari
iframe.height=10;
iframe.height = iframe.contentDocument.body.offsetHeight;
}
}
这样在IE、FireFox和Chrome中就都好使了。
- iframe 设置iframe高度
- 动态设置iframe高度(iframe高度自适应)
- IFrame高度设置
- 设置iframe高度自适应
- iframe(2) --- 动态设置iframe高度
- 动态设置iframe的高度
- javascript设置iframe的高度
- 动态设置IFrame的高度
- jquery获取、设置iframe高度
- iframe高度自适应的设置
- 动态设置iframe的高度
- iframe 高度设置、iframe 自适应高度方法总结
- Iframe设置高度为100%问题!!!!【转】
- 将iframe设置为自适应高度
- w3c标准下iframe 设置高度100%
- 设置HTML中的Iframe框架自适应高度
- 有关动态设置iframe高度问题
- HTML教程:如何设置Iframe自适应高度
- 让Myeclipse支持jQuery、Ext等主流框架自动完成、调试功能,Myeclipse集成Apatana
- HDU 2642 二维树状数组问题
- Linux命令之pwd
- android与jsp http post方式通信
- SQL SERVER错误代码大全
- IFrame高度设置
- SEO优化(增加搜索爬虫)
- 备份恢复IBM DB2数据库的基本步骤-----文件转自DB2china
- QT国际化机制的相互矛盾的地方[Q_PROPERTY与tr函数]
- 鼠标放到控件上 DIV悬浮提示效果(四种)
- C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- ClipboardService(CBS)中的权限管理
- setTag()和getTag()应用
- mysql int(3)与int(11)的区别