Jump to content

Back button takes you to same place on page


xProteuSx

Recommended Posts

I have a PHP based website where some of the pages get quite long, so you need to scroll down and down and down.  Now, what I would like is that if someone scrolls down one of the long pages, clicks a link, and hits the back button, the page is there anew, but the visitor is already scrolled down to the point where he clicked on the link.  Right now if you hit the back button the you go back a page, but to the top of it.  Any ideas how this is done?

Link to comment
Share on other sites

No, anchor links is not what I was thinking.  Anchor links can be used to get from one part of a page to another part of the same page real quick.  I know this, and even use it occasionally.  However, this doesn't help me as far as the Back button goes.

Link to comment
Share on other sites

You know, this seems to be automatically 'on' in Internet Explorer.  Mozilla is fussy, and takes you back to the top of any page you go 'Back' to.

 

I thought it might just be a browser thing, until I realized that on eBay it works, even in Mozilla/Firefox.

Link to comment
Share on other sites

Although it may be bad practice, you can use this onclick attribute on the link:

 

<a href="page_url" onclick="history.go(-1); return false;">Back</a>

 

Haven't used it myself before, so I'm not sure how it precisely works, but you could try it out.

 

The elegant solution would be to use anchor links like redarrow suggested. Just add a name attribute to each link on the long page, and then include that name in the back button link on each individual page. Like:

 

Long page (long.php)

Bla bla <a href="small.php" name="somename">first link</a> bla bla. More text and links.

 

Individual page (small.php)

Some more text. <a href="long.php#somename">Back button<a>.

 

Or simply remove the back button, and force the user to use the browser's back button. That should take them back to exactly where they clicked the link on the long page.

Link to comment
Share on other sites

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.