【问题标题】:move to top of page when changing iframe content without using JavaScript在不使用 JavaScript 更改 iframe 内容时移动到页面顶部
【发布时间】:2013-12-24 09:35:07
【问题描述】:

我检查了以下问题: How do I Scroll parent page to top when child page is click within iframe? 和 Scrolling parent page when remote content loads in 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)?

【问题讨论】:

  • 我觉得没有js没有办法,为什么不用js呢?

标签: html iframe


【解决方案1】:

你可能想试试这段代码:

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

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

【讨论】:

    【解决方案2】:

    我认为您将不得不使用 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 会自动触发更新。

    【讨论】:

    • 如果没有 javascript,您尝试做的事情是不可能的。
    猜你喜欢
    • 2017-12-07
    • 2015-02-14
    • 2016-04-18
    • 2013-03-06
    • 2023-03-26
    • 1970-01-01
    • 2020-08-08
    • 2023-03-24
    • 2014-10-30
    相关资源
    最近更新 更多