move to top of page when changing iframe content w

2019-08-10 11:48发布

I have checked the questions: How do I Scroll parent page to top when child page is click within iframe? and Scrolling parent page when remote content loads in iframe But I would like to avoid javascript if possible. I have an iframe

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

And some links that point to it:

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

My problem is that some of the links are far below in the page and when they are "clicked" the iframe is not visible or only partially visible.

How can I force the page to scroll to the top without using javascript?

I already have a div at the top of the page with id=Fascione that I use in my footer to "go to the top"

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

and I would like to re-use it; is this possible (again without javascript)?

标签: html iframe
2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-10 11:52

I think you will have to use Javascript, which isn't that hard. Here's what to change:

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

The href="#Fascione" will push the page to the top, and changing the SRC on the iframe will automatically trigger the update.

查看更多
beautiful°
3楼-- · 2019-08-10 12:10

You may want to try this piece of code:

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

This is a easy way to scroll the page to the top.

查看更多
登录 后发表回答