六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 225|回复: 0

兼容IE和FireFox的iframe 自动高度脚本

[复制链接]

升级  16.67%

74

主题

74

主题

74

主题

举人

Rank: 3Rank: 3

积分
250
 楼主| 发表于 2013-2-8 00:45:43 | 显示全部楼层 |阅读模式
<iframe name="mainframe" id="mainframe" src=""  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"  border="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="732"></iframe>

</body>
</html>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表