返回首页当前位置:首页 >> 网站建设 >> 正文

让Iframe自适应高度(根目录下管用)

文章来自: | 发表时间:2007-12-21 16:44:32

让Iframe自适应高度(根目录下管用)

经常碰到使用框架嵌入页面时无法做到高度自适应,以下这个方法可以实现:
<script type="text/javascript">
function SetWinHeight(obj)
{
    var win=obj;
    if (document.getElementById)
    {
        if (win && !window.opera)
            {
                if (win.contentDocument && win.contentDocument.body.offsetHeight) win.height = win.contentDocument.body.offsetHeight;
                else if(win.Document && win.Document.body.scrollHeight)
                win.height = win.Document.body.scrollHeight;
            }
    }
}
</script>



<iframe frameborder="0" name="win" id="win" src="index.html" onload="Javascript:SetWinHeight(this)" align="top" width="100%" scrolling="no"></iframe>