简体   繁体   中英

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. ie 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.

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM