内嵌框架iframe在火狐ff下自适高度(ie6、ie7、ff都正常)JS

添加评论 2009年9月18日

方法一:Demo:  iframe1

1.脚本

在调用iframe的页面添加脚本

<script type=”text/javascript”>

function reinitIframe(){

var iframe = document.getElementById(“frame_content”);

try{

iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;

}catch (ex){}

}

window.setInterval(“reinitIframe()”, 200);

</script>

2.调用

<iframe id=”frame_content” src=”d.htm” scrolling=”no” frameborder=”0″ style=”width:100%; _height:100%;”></iframe>

 

方法二(推荐):Demo:iframe2

1.脚本

在调用iframe的页面添加脚本

<script type=”text/javascript”>

function ReSizeiFrame(iframe)
{
if(iframe && !window.opera)
{
   iframe.style.display = “block”;
   if(iframe.contentDocument && iframe.contentWindow.document.documentElement.scrollHeight)
   {
    iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;//设置iframe在火狐下高度
   }
   else if (iframe.Document && iframe.Document.body.scrollHeight)
   {
    iframe.height = iframe.Document.body.scrollHeight;//设置iframe在ie下的高度

   }
}
}

</script>

2.调用

<iframe id=”frame_content” src=”d.htm” scrolling=”no” frameborder=”0″ onload=”ReSizeiFrame(this);” style=”width:100%;”></iframe>

示例下载:iframe-js.rar

Share and Enjoy:
  • del.icio.us
  • Facebook
  • TwitThis
  • 百度搜藏
  • 饭否
  • 收客
  • QQ书签
  • 我挖网
  • DigLog
  • 365Key网摘
  • BlinkList
  • blogmarks
  • BlogMemes
  • Blogosphere News
  • Digg
  • Google Bookmarks
  • MyShare
  • POCO网摘
  • Yahoo! Buzz
  • YahooMyWeb
  • Yigg
  1. 还没有评论.想坐沙发?
  1. 还没有 trackbacks
订阅评论