Jump to content

Recommended Posts

I have a web page where users can scroll down to see the content. Along the length of the page are links to another page. When the user clicks a link and gets to the next page they are presented a link to 'return to the previous page'. If they click that link it takes them back to the original page just fine but it returns them to the top of the page. I would like them to return to the same spot they were at when they exited the original page. When you use the 'back' button on the browser it does this. I don't know what the term is for it so I don't even know where to start looking for a way to do it. Any help would be appreciated.

 

Thanks

Steve

Link to comment
https://forums.phpfreaks.com/topic/315566-return-to-original-place-on-a-web-page/
Share on other sites

Use JavaScript to make the link work as a back button instead of a normal link back to the page.  You can leave your link as it is now so users that have JS disabled will still go back, just not to the same position.

HTML:

<a href="previous.html" class="return-link">Return</a>

Script:

//Using jQuery
$('.return-link').click(function(e){
  e.preventDefault();
  history.back();
});

 

Haven't used it in awhile but there is a use of the html <a> tag to do just what you want.  Create anchors in the page where you want to come back to and then use the same name value in your call back to the page.  Read up on it.

<a href="#section2">Go to Section 2</a>
 

and

<h2 id="section2">Section 2</h2>

When you click on the anchor tag it will send you to the place where there is something with an id matching the href value.  You can create an anchor that directs you to another page also, just append the #xxx to your url as in:

<a href="mywebpage.com#section2">Go to new page</a>

Actually, it's the name attribute to define an area of the page scroll-wise.

<a name="middle-of-page">

Then you can have your link with the name in it

<a href="#middle-of-page">Click to go to middle of page</a>

For external usage, just put the page url.

<a href="page2.html#middle-of-page">Click to go to middle of Page 2</a>

 

@Barand I suppose you're right :)

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes

Ironically, that page didn't scroll to Attributes section when I clicked the link.

image.png

Using that site as an example, it looks like the id can be on hN elements

image.png

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.