在一个页面中嵌入一个html禁止整个页面产生滚动条解决方案

来源:互联网 发布:刀锋女王 知乎 编辑:程序博客网 时间:2024/06/06 15:24

          在页面要显示嵌入的html的地方加入两个div层,div层为嵌套的关系,在内部的div中加一个iframe,在iframe中嵌入一个已生成好的html,并让html填充慢iframe

       设计如下:

#content {            overflow-y: auto;            overflow-x: hidden;            border: 1px solid #ccc;            height:600px;        } #content, #contents {       width: 80%;       margin-left: auto;        margin-right: auto;}
<div id="content">    <div id="contents" >      <iframe id="myFrame" name="_blank" frameborder="0"  scrolling="no" onload=" SetWinHeight(this)" src="嵌入的html的相对地址">      </iframe>     </div></div>

function SetWinHeight(obj) {            if (document.getElementById) {                if (obj && !window.opera) {                    if (obj.contentDocument && obj.contentDocument.body.offsetHeight)                        obj.height = obj.contentDocument.body.offsetHeight;                    else if (obj.Document && obj.Document.body.scrollHeight)                        obj.height = obj.Document.body.scrollHeight;                }            }        }

       效果如下:


注:
onload="this.height=myFrame.document.body.scrollHeight"

这样写在IE下是可以的,但是在FF和Google下是不可以正常显示的; Iframe在跨域时也是不能正常显示的。如下图:




2 0
原创粉丝点击