WebEnh

.net7 mvc jquery bootstrap json 学习中 第一次学PHP,正在研究中。自学进行时... ... 我的博客 https://enhweb.github.io/ 不错的皮肤:darkgreentrip,iMetro_HD
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

jQuery解决iframe高度自适应代码

Posted on 2016-12-27 02:11  WebEnh  阅读(528)  评论(0编辑  收藏  举报
网上查了好多用着都不行,自己搞定了:在包含iframe的页面中加入以下脚本,基本思想是在iframe加载内容后重新设置高度,下面代码尽在IE6中用过,没在其他浏览器中测试。

 

代码如下:

<script type="text/javascript"> 
<!-- 
$( 
    function() 
    {                     
     //iframe高度随内容自动调整 
        $('.main').load( 
         function() 
            { 
                $(this).height($(this).contents().find("body").attr('scrollHeight')); 
            } 
        ); 
    } 
);      
// --> 
</script>