iframe 自适应高度js

来源:互联网 发布:购买软件服务协议 编辑:程序博客网 时间:2024/06/10 03:33
 

<script type="text/javascript" language="javascript">  
        function SetCwinHeight(obj) {
            var cwin = obj;
            if (document.getElementById) {
                if (cwin && !window.opera) {
                    if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
                        cwin.height = cwin.contentDocument.body.offsetHeight + 20; //FF NS
                    else if (cwin.Document && cwin.Document.body.scrollHeight)
                        cwin.height = cwin.Document.body.scrollHeight + 10; //IE
                }
                else {
                    if (cwin.contentWindow.document && cwin.contentWindow.document.body.scrollHeight)
                        cwin.height = cwin.contentWindow.document.body.scrollHeight; //Opera
                }
            }
        }

    </script>

<iframe id="id" name="name" frameborder="0" width="750px" scrolling="no"
                    onload="SetCwinHeight(this)"></iframe>