-1

我知道使用 iframe 并不总是最好的主意,但就我而言,它使事情变得更容易。我有一个网站 A,其中包含指向同一网站上其他部分的链接(使用<a name=...)。我有一个秒站点 B,它有一个包含 A 的 iframe。一切正常,除了页面超链接,如果你点击它们,什么也不会发生。

有谁知道在 iframe 中是否可以使用命名超链接?如果是的话,如何让它们工作。

编辑:

好像我说的不够清楚。该文件名为 test.html (http://www.domain.com/embedded/test.html),顶部包含一个超链接

<a href="#examples">Examples</a>

然后在最后的某个地方有一个链接

<a name="examples"></a>

因此,当您单击顶部链接时,页面应向下滚动到底部链接。我有第二页(http://www.domain.com/index.html),其中包含 test.html 的 iframe。将鼠标悬停在链接上(在 iframe 内)时,它会显示http://www.domain.com/embedded/test.html#examples。我不是 iframe 专家,但这个链接似乎更愿意重定向到实际文件(到 #examples),而不是跳转到 iframe 内。正如我之前所说,单击链接时没有任何反应。刚刚在 Chrome 中测试,它可以工作。似乎这是 Firefox 特有的问题。

4

2 回答 2

1

您问题的这些部分让我闻到了一些东西:“指向同一站点上其他部分的链接(使用<a name=...)”和“命名超链接”......

用于移动到同一页面其他部分的超链接:

<a href="#BOOKMARK">Goto BOOKMARK</a>

以及同一页面中其他地方的锚点(书签) :

<a name="BOOKMARK"></a>

无论它们是否显示在每个 HTML 文档中,它们都iframe适用。

于 2012-12-04T13:26:46.847 回答
0

I had a similar problem. I too wanted a link in an embedded page to point to a bookmark in the containing page. But I am not sure if our circumstances are exactly the same.

A local link such as

<a href="#BOOKMARK">

will only look for an anchor in the same page as the link, i.e. in the embedded page. An approach such as

<a href="containing-page.html#BOOKMARK" target="top">

will only work if your link always references the same containing page. (The target needs to be specified, to display the page outside the iframe.) I am not sure if this will meet your needs.

If you want to re-use a common bookmark name in different containing pages, as I do, the design effectively requires the destination url to be treated as a variable, and that cannot be done using pure HTML. It requires javascript or similar.

It was in fact more elegant for me to add the bookmark link to the containing page, so that I do not need to standardize my bookmark names. This does not even need javascript, just a bit of css.

What I did was to position the bookmark link over the embedded display, so that it looks like it is part of the embedded page. In this example, the iframe is fixed at the top of the page and the bookmark link positioned over its top left corner.

<iframe style="position:fixed; left:0pt; top:0pt;" src="embedded-page.html"></iframe>
<div style="position:fixed; left:0pt; top:0pt;">
    <a href="#BOOKMARK">My Bookmark</a>
</div>

With a bit of css refinement, this gives some flexibility of layout. For your issue, you may need to stick with javascript.

于 2019-04-21T08:57:12.870 回答