redirecting to a specific page when clicking browser's back button
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 wit开发者_Go百科hout the use of (yet another) plugin.thanks.
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
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')
精彩评论