简体   繁体   中英

Go Back to the Previous Location on Previous Page when Clicking Browser Back Button

This is what I want to implement:

On page a, click the link, go to page b,showing everything on page b from the beginning. Click browser back button, it goes back to page a and showing contents from the link position.

This is what I got now:

It happens between two aspx pages,

1、On the first page, http://xxxx/default.aspx#project/page/home , there is a link < a href="#page/test" >TEST< / a >

2、So When I click this link, it will jump to http://xxxx/default.aspx#project/page/test . But it seems like the browser remembers the link position on page/home and directly jump to the same position on page/test,instead of showing all the contents from the very beginning.

3、When I click browser back button, to the previous page, it also cannot go back to that link position.

Additional information: I changed the < a href="#page/test" >TEST< / a> to < a href="https://stackoverflow.com/questions/1215449/browser-does-not-remember-position-of-page-last-viewed" >TEST< / a >, it worked just fine. So I think it is because of the aspx pages and the hashtag.

I have tried this, it will cause showing two pages at the same time(one on the left and one on the right) Take User Back to Where They Scrolled to on previous page when clicking Browser Back Button

Please help, thank you.

To use an <a> tag to re-position the page, you need to have an element with an id attribute that matches the text following # in the link:

<!DOCTYPE html>
<html>
<body>

<h2 id="thetop">Top of page!</h2>

<p>Text here</p>

<a href="#thetop">Go to top</a>
</body>
</html>

Before HTML5, this was done with another <a> that included a name attribute:

<!DOCTYPE html>
<html>
<body>

<a name="thetop">Top of page!</a>

<p>Text here</p>

<a href="#thetop">Go to top</a>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM