`
wing123
  • 浏览: 789513 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

iframe高度自适应

    博客分类:
  • HTML
 
阅读更多

好像只能用JS来控制 我用的就是这段了

<script type="text/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>

 

 

html

 

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

 

 

注意:width="750px" -- 按自己的需要改下

 

一般的iframe 宽度不会改变了 只会改变页面内容的高度
因值的填充问题

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics