简体   繁体   中英

back button not working after javascript redirect

I have a widget which is embedded in random sites. when the user clicks I call the server to update the click occured and the server returns redirect to the correct page. The problem is that the Back button of the browser no longer works.

I use location.href for the redirect.

I tried location.replace -which keeps the back button , but it goes to the page before the page in which the widget was clicked (it replaces it with the new page).

How can I do the page switch after reporting to the server and still allow the back button to work?

You cannot go back to a page that auto-redirects. That's just a broken back button and a frustrated user.

User goes to page A.
User clicks on link to page B.
Page B automatically redirects to page C with window.location.
User hits back button and momentarily goes back to page B.
Page B automatically redirects to page C with window.location.
User hits back button and momentarily goes back to page B.
Page B automatically redirects to page C with window.location.
User is sad.

Obviously this doesn't work. It has to work like this instead:

User goes to page A.
User clicks on link to page B.
Page B automatically redirects to page C with window.location.replace().
User hits back button and goes back to page A.
User is happy.

You must auto-redirect with window.location.replace() if you want the back button to work.

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