2

it's a bit of a nooby question, but there it goes:
i have a site where the user can only navigate from page to page via next and back buttons. i.e there is a wizard the user must follow. part of the wizard includes different pages and part includes the same page but with changing divs (but from user experience its a different page).
i would like to simply redirect the user to the first page of the wizard, whenever he clicks on the browser's back button.
if possible and simple, i prefer doing so without the use of (yet another) plugin.

thanks.

Salmonela
  • 77
  • 2
  • 6
  • possible duplicate of [Is there a way to catch the back button event in javascript?](http://stackoverflow.com/questions/136937/is-there-a-way-to-catch-the-back-button-event-in-javascript) – Kon Jul 26 '11 at 15:27

2 Answers2

0

It's not possible to prevent the default behavior of the browser's back button - no browser allows that because it would pose potential security risks and a bad user experience.

With that said, there are tricks out there that may satisfy your needs.
Check this out: Detecting Back Button/Hash Change in URL

Community
  • 1
  • 1
Kon
  • 27,113
  • 11
  • 60
  • 86
  • hi kon, i'm not trying to prevent the browser's back button. all i'm trying to do is and another "history mark" that will point to the fist page... – Salmonela Jul 26 '11 at 15:17
  • and since my goal is fairly simple i'm trying to refrain from using plugins which is what they suggest in the link you have provided. thanks :) – Salmonela Jul 26 '11 at 15:17
  • You don't need to use any plugins. I didn't send you there for any specific answer, but just in general. Here's what you want: http://stackoverflow.com/questions/136937/is-there-a-way-to-catch-the-back-button-event-in-javascript In fact, this question is a duplicate. – Kon Jul 26 '11 at 15:26
  • it's not a duplicate question and the link you have provided does not include an answer to my question. i'm not looking for a way to poll the location.hash. my question was simpler, how do I add a reference to the first page... – Salmonela Jul 26 '11 at 15:55
0

There are a lot of ways but since you don't want to use plugins (I guess libraries too) you can just use the browser's function for that:

window.location

Use this for reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/location

Or if you want to use a library, I recommend going for page.js since it's really easy to use:

for example:

page.redirect('/home')