<iframe name="mainframe" id="mainframe" src="" onload="this.height =document.frames['mainframe'].document.body.scrollHeight" border="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="732"></iframe>这种方法只能在ie上面有用,在firefox中并不支持,因此我做了一个兼容IE和FireFox的iframe 自动高度脚本和大家分享!
<html>
<head>
<title>兼容IE和FireFox的iframe 自动高度脚本</title>
<link href="/zbh/css/style.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="/share/pic/logo.ico">
<link rel="Bookmark" href="/share/pic/logo.ico">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<script>
var FFextraHeight = 0;
if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
FFextraHeight = 16;
}
function ReSizeiFrame(iframe)
{
if(iframe && !window.opera)
{
iframe.style.display = "block";
if(iframe.contentDocument && iframe.contentDocument.body.offsetHeight)
{
iframe.height = iframe.contentDocument.body.offsetHeight + FFextraHeight;
}
else if (iframe.Document && iframe.Document.body.scrollHeight)
{
iframe.height = iframe.Document.body.scrollHeight;
alert(iframe.Document.body.scrollHeight);
}
}
}
</script>
<iframe name="mainframe" id="mainframe" src="/share/aa.html" onload="ReSizeiFrame(this)" border="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="732"></iframe>
</body>
</html>
分享到:
相关推荐
因为有一个项目要用到iframe自适应高度,网上搜索了以下结果无数,不过看来看去都是那...iframe自适应高度,亲测完美兼容IE6_7_8_9,Chrome谷歌浏览器,Opera欧朋浏览器,FireFox火狐浏览器,Mac Safari浏览器等五大浏览器
CSS兼容IE和Firefox的技巧集合
iframe和firefox的兼容。
兼容IE和Firefox获得keyBoardEvent对象的键值
DIV中兼容IE和Firefox的mouseleaves事件
让CSS兼容IE和Firefox的技巧集合,有了它IE不在是bug 嘿嘿
CSS兼容IE和FireCSS兼容IE和Firefox的技巧集合fox的技巧集合
设为首页、加入收藏代码,兼容IE和fireFox设为首页、加入收藏代码,兼容IE和fireFox
为了解决兼容性问题;我弄了一下午;兼容IE和firefox的弹出层.zip
BlueBala » 兼容IE和Firefox的事件模型(拖动)
兼容IE和Firefox的Html在线编辑器!
符合标准的间隙间歇滚动代码(兼容IE和FireFox).htm 符合标准的间隙间歇滚动代码(兼容IE和FireFox).htm
兼容ie及firefox的flash相册,不容错过!希望能给大家帮助!
Javascript的IE和Firefox(火狐)兼容性解决方案
最让页面设计师头痛的就是兼容问题,你想知道ie和火狐一起兼容吗,来学习一下吧
兼容IE和FireFox的event(事件)的对象获得,直接下载引用即可
兼容IE与FireFox的一些JS代码资料