【问题标题】:How to remove double scroll bars when embedding a page?嵌入页面时如何删除双滚动条?
【发布时间】:2015-11-02 17:43:39
【问题描述】:

这里有一些与此类似的问题,但他们的解决方案似乎对我不起作用。基本上我已经将一个页面嵌入到网站上的一个页面中,并且得到了双滚动条,一个在 iframe 中,一个在它嵌入的页面中。我想要的是取消 iframe 中的滚动条并制作它扩展了 iframe 的 100%,并且只在我的页面中使用滚动条。所以很难说它是一个嵌入式页面。我正在使用 Bootstrap 的 iframe 嵌入类来保持页面响应。如果我需要取消该课程,那很好。这是html。

<div class="container">
<div class="main">
  <div class="inner-main">
      <h1>Page Heading</h1>
      <div class="row">
        <div class="col-lg-12">
            <div class="embed-responsive embed-responsive-16by9">
              <iframe  class="embed-responsive-item" src="mylink"></iframe>
            </div>
        </div>
      </div>
    </div>
  </div>
</div>  

有没有简单的方法来做到这一点?嵌入的页面相当长,所以我需要它来将我的页面一直向下推。

这是我最终做的:

<iframe onload="scroll(0,0);" class="embed-responsive-item" src="mylink"></iframe>

CSS

.embed-responsive-16by9 {
    height: 6060px;
    }

iframe {
    width: 100%;
    display: block;
    height: 6060px;

  }

我会寻找更好的方法来做到这一点

【问题讨论】:

  • 您需要获取内页的高度并将高度分配给iframe。这可以通过使用 jquery 来完成。该脚本将在 iframe 页面上运行,并将调用父页面或 window.parent.$(elementid).attr(attributeName); 上的脚本
  • 我最终基本上只是用 CSS 做这个。将 iframe 高度设置为原始页面的高度。
  • 能否分享一下代码
  • 当然我会编辑我原来的问题。然而,这不是理想的解决方案。当您切换到 iframe 中的另一个页面时,您在底部有大量空白区域,但乍一看似乎我想要它,现在它必须这样做。
  • 能否请您检查代码 $('#iframe_id').load(function () { $(this).height($(this).contents().height()); $ (this).width($(this).contents().width()); });如果您在 iframe 中重新加载页面,这会有所帮助吗

标签: html css twitter-bootstrap iframe


【解决方案1】:

编辑:删除了我的其他答案,我误读了问题。

除非 iFrame 和父页面在同一个域上,否则很难做到,这样的事情应该可以工作:

Resizing iframe to fit its content

【讨论】:

【解决方案2】:

如果您不使用跨域的内容,您的脚本将是

$('#iframe_id').load(function () {
    $(this).height($(this).contents().height());
    $(this).width($(this).contents().width());
});

【讨论】:

    猜你喜欢
    • 2021-10-21
    • 2023-01-11
    • 2017-12-31
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 2011-05-26
    相关资源
    最近更新 更多