"Back to previous page" link

  • 1
  • Idea
  • Updated 7 years ago
  • Not Planned
I 've tried several times to get a "Previous page" link onto my site, without much success. I finally found one in Javascript, which did the job but looked rather clumsy and I found some sites didn't allow Javascript.
But now I've found a single-line HTML function that does the same thing, more simply. Here it is:
<!--
<a href="#" onclick="history.go(-1)">Previous page</a>
-->
Many of you probably have this already, but some may find it useful.
Photo of Philip Taylor

Philip Taylor

  • 355 Posts
  • 66 Reply Likes
  • happy

Posted 7 years ago

  • 1
Photo of Gop

Gop

  • 7473 Posts
  • 2115 Reply Likes
Good find Philip but it really is Javascript within HTML :)

"onclick" calls a Javascript function being the "go(-1)" so if people have Javascript disabled it will probably just stop or ignore it I guess.
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
Thanks for the tip, Philip!

Gop is right, onclick is just an inline click event of JavaScript, same with onsubmit, onmousedown, etc.

Unfortunately there's not really any pure-HTML solutions to anything that you click on because HTML is just structure and it doesn't handle user interaction.

Also, there is also a "back" method of the JavaScript history object where you can do history.back(); if you didn't know (this probably wouldn't be any use to you guys though as .go(-1) works the same)

@Gop: Yep, it will just be ignored and not do anything when you click it to users that don't have JavaScript enabled. (who even has JavaScript disabled these days? I hate it when people have it disabled because my web apps don't work in it! And not to mention, Facebook, Twitter, Yola, GS forums, Gmail, Yahoo Mail, Web chats, etc. don't work when JavaScript is disabled either)

Nathan
Photo of Gop

Gop

  • 7473 Posts
  • 2115 Reply Likes
Thanks Nathan maestro. Always good to learn from your knowledge and experience.
Photo of Philip Taylor

Philip Taylor

  • 355 Posts
  • 66 Reply Likes
Ouch ! Sorry.