【问题标题】:Scroll iframe to anchor without id field滚动 iframe 到没有 id 字段的锚点
【发布时间】:2016-09-01 06:40:33
【问题描述】:

我正在页面上加载一个 iframe,我只想显示其中的一部分,问题是,我想在 iframe 中显示的位置不包含 id 字段,所以下面的代码不起作用.

<iframe src"thedoamin.com #anchor" />

我尝试将 id 字段添加到我想在源域中显示的部分,但该部分本身是一个插件,可以加载一些其他 javascript。所以上面的 iframe 根本不会滚动到 id 锚点。

我认为问题在于 iframe 首先在我的页面中加载,并且它在 iframe 中找不到 id 字段,因为该部分尚未加载,所以它没有做任何事情。感觉自己陷入了无限循环。

如何只显示 iframe 的一部分而没有 id 字段????

我也尝试过使用.load()函数,但我想显示的部分不仅仅是html,它也依赖于其他javascript和css,所以它不能正常显示。

【问题讨论】:

  • 请分享您之前尝试过的代码
  • 另外,您的链接应采用http://thedomain.com/#anchorpage.html#anchor 格式 - 如果 iframe 内容来自同一来源,您或许可以在渲染后使用 jQuery 提取您需要的内容跨度>
  • @mplungjan 我已经试过了,它不起作用,我尝试了页面上的其他 id,不管它的 /# 或 html# 还是 html# 都有效,所以我不不认为这是问题
  • 您可以使用带有max-widthmax-heightoverflow:hidden 的div,然后使用margin-topmargin-left 将您的iframe 放置在该div 内,以您想要显示的任何位置。
  • @Arun 这就是要尝试的一切......除非你想要 .load 功能。 $("#test").load("thedomain.com #anchor");

标签: javascript jquery html iframe


【解决方案1】:

这是我评论的更新答案:

您可以尝试在 div 中使用 iframe,然后根据该 div 设置 iframe 的位置。

<div style="overflow: hidden; max-width: 736px;">
  <iframe scrolling="no" src="your_page" style="margin-left:-185px; height:859px; margin-top:-533px; width:926px;">
  </iframe>
</div>

【讨论】:

    猜你喜欢
    • 2017-03-11
    • 2020-10-17
    • 1970-01-01
    • 2018-02-23
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多