首页 文章

如何使用不同高度的页面动态调整iFrame的大小?

提问于
浏览
1

我正在使用此代码根据远程站点的内容动态调整iFrame的大小:

http://solidgone.org/Set-IFRAME-height-based-on-size-of-remotely-loaded-content

但是,在该远程站点上,还有其他页面 . 当我点击远程站点上的链接(在iFrame内)时,高度不会相应地改变 . 相反,它使用我们最初在iFrame上设置的页面高度 . 在这种情况下,它使用remote.php的高度(这是非常高):

<iframe id='local-iframe' width='1' height='1' frameborder='0' scrolling='no' src ='http://remotesite.com/remote.php'></iframe>
</iframe>

另一件事是,即使我在iFrame上指示了滚动='否',一旦我点击了iFrame内部的链接,滚动条就会重新出现 .

有没有解决这个问题的方法?我们做错了什么?

2 回答

  • 0

    这个网站(下面)的代码对我有用,虽然我正在努力让边界消失......

    http://ramanisandeep.wordpress.com/2009/12/16/how-to-dynamically-adjust-an-iframe’s-height/


    在页面上插入iframe

    <iframe scrolling='no' frameborder='0' id='frmid' src=’getad.aspx'
             onload='javascript:resizeIframe(this);'>
    </iframe>
    

    使用此javascript根据子页面的高度和宽度调整iframe的大小

    <script language="javascript" type="text/javascript">
     function resizeIframe(obj)
     {
       obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
       obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';
     }
     </script>
    
  • 2

    我认为你现在无法以任何可能的方式直接访问IFRAME的内容 . 因此,你也无法直接检测它的高度 .

    正如您可以从您所指的文章中读到的那样,作者已经写了一个更新:http://solidgone.org/Redux-Set-IFRAME-height-based-on-size-of-remotely-loaded-content

    如果我理解正确的话,它正在以高度作为本地资源的参数发出请求,这有助于设置高度 .

相关问题