1

我检查了以下问题: 在 iframe 中单击子页面时,如何将父页面滚动到顶部?在 iframe 中加载远程内容时滚动父页面 但我想尽可能避免使用 javascript。我有一个 iframe

<iframe name="MapFrame" id="MapFrameID" src="http://maps.google.ch/maps?f=q&..."></iframe>

还有一些指向它的链接:

<a href="http://maps.google.com/maps?q=St%C3%A4mpflistr.+28,+3052+Zollikofen..." target="MapFrame">mostra sulla mappa</a>

我的问题是一些链接在页面下方很远,当它们被“点击”时,iframe 不可见或仅部分可见。

如何在不使用 javascript 的情况下强制页面滚动到顶部?

我已经在页面顶部有一个 id=Fascione 的 div,我在页脚中使用它来“转到顶部”

<a href="#Fascione"><img class="NoBackground" alt="Go to top" src="images/common/go_up_black.png" width="30" height="30"></a>

我想重复使用它;这可能吗(再次没有javascript)?

4

2 回答 2

1

您可能想尝试这段代码:

<a href="#Fascione" onclick="parent.scrollTo(0,0);">Go to the top</a>

这是一种将页面滚动到顶部的简单方法。

于 2012-11-13T17:39:27.843 回答
0

我认为您将不得不使用Javascript,这并不难。以下是要更改的内容:

<a href="#Fascione" onclick="var map = document.getElementById('MapFrameID'); map.src = 'http://maps.gooogle.com/maps...'">mostra sulla mappa</a>

href="#Fascione" 会将页面推到顶部,更改 iframe 上的 SRC 会自动触发更新。

于 2012-06-21T16:02:51.723 回答