Iframe 自适应高度代码

来源:互联网 发布:阿里云终端管理 编辑:程序博客网 时间:2024/05/18 01:00

Iframe 自适应高度

code 1:
<div class="center" style="padding-left:10px">
    //Iframe窗口自适应高度 兼容IE6.0、Chrome、FF3.0以上
    <script type="text/javascript" language="javascript">
    function iframeFitHeight(iframe)
    {
        try {
             var win = iframe.name ? window.frames[iframe.name] : iframe.contentWindow;
             iframe.style.height = win.document.body.scrollHeight + "px";
            }
        catch(e){}
    }
    </script>
    //在iframer 的父窗口 利用onload() 事件进行调用
    <iframe id="boxscore_content" name="boxscore_name" frameborder="0"  width="100%" src="http://www.domain.com/includes/boxscore_today.php" onLoad="iframeFitHeight(this)"></iframe>
</div>

code 2:
使用jQuery autoHeight plugin来实现
基本代码:
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript" src="autoHeight.js"></script>
<iframe src="http://www.domain.com/boxscore.php" width="300" frameborder="0" scrolling="auto" class="autoHeight" name="iframe"></iframe>

原创粉丝点击