iframe引用 给定了高度···随内容增长

qq_31773471 2015-10-15 10:28:39
login.aspx页面中分了三部分头,中,底<iframe id="sli" scrolling="no" height=867> iframe 的内容是中间,现在iframe 有个页面有jQuery 滑动效果,因为写了867高度内容显示不完全,希望能随内容来改变<iframe id="sli" scrolling="no" height=867> 高度····求大神帮忙
...全文
176 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
iframe.height =200;// 先设置为一个很小的值,如200,让iframe先恢复后重设高度
setTimeout(function(){
iframe.height =  iframe.contentWindow.document.documentElement.scrollHeight;
},100);//防止浏览器优化代码,直接执行这句,所以用计时器延时执行
DaveLeeCN 2015-10-16
  • 打赏
  • 举报
回复
你把height去掉它就可以根据内容来设置高度,but因为你设置不用滚动条,所以这样的话超出屏幕的部分会不显示。
qq_31773471 2015-10-16
  • 打赏
  • 举报
回复
<script type="text/javascript"> function reinitIframe(){ var iframe = document.getElementById("sli"); try{ iframe.height = iframe.contentWindow.document.documentElement.scrollHeight; }catch (ex){} } window.setInterval("reinitIframe()", 200); </script> <iframe id="sli" scrolling="auto" frameborder="0" runat="server" name="sli" width="1150px" height="867px" style="border: none" ></iframe> 在谷歌上我点击iframe 页的滑动效果高度变了,取消滑动它的高度也会变回height=867px,但是在ie和ff取消滑动效果,高度没有变回867px```有什么办法吗
  • 打赏
  • 举报
回复
iframe添加onload事件,然后通过iframe加载的内容滚动高重设iframe的高度(注意iframe加载的页面不能跨域,要不获取不到iframe滚动高度)
<iframe onload="resetHeight(this)"></iframe>
<script>
    function resetHeight(i) {
        var h = Math.max(i.contentWindow.document.body.scrollHeight, i.contentWindow.documentElement.body.scrollHeight);
        i.style.heigh=h+'px'
    }
</script>

87,984

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧