欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

jQuery,js实现Iframe自适应高度(兼容多浏览)

// 我们在aa.html里面有个iframe,加载内容为bb.html 

Html代码  收藏代码
  1. <iframe id="frame_con" src="bb.html" frameborder=0 scrolling=no style="margin-left:0px;margin-top:-3px;width:785px;height:550px;float:right;"></iframe>  



方式一 

Js代码  收藏代码
  1. //引入jQuery  

  2. <script src="http://res.func.fetionpictest.com/js/public/jquery-1.3.2.min.js?2011122701" type="text/javascript"></script>  

  3. <script type="text/javascript">  

  4.           //document.domain = "fx-func.com";//指向根域  

  5.          $(window.parent.document).find("#frame_con").load(function(){//绑定事件  

  6.          var main = $(window.parent.document).find("#frame_con");//找到iframe对象  

  7.          var thisheight = $(document).height()+30;//获取页面高度  

  8.          main.height(thisheight < 500 ? 500 : thisheight);  

  9. //为iframe高度赋值如果高度小于500,则等于500,反之不限高,自适应  

  10.                 });  

  11.      </script>  



方式二 

Js代码  收藏代码
  1. $("#frame_con").load(function(){  

  2.     var thisheight = $(this).contents().find("body").height()+30;  

  3.     $(this).height(thisheight < 500 ? 500 : thisheight);  

  4. });  


来自  http://qiaolevip.iteye.com/blog/1674859

普通分类: