javascript重定向后后退按钮不工作

back button not working after javascript redirect

本文关键字:工作 按钮 重定向 javascript      更新时间:2023-09-26

我有一个嵌入随机站点的小部件。当用户单击时,我调用服务器更新发生的单击,服务器返回到正确页面的重定向。问题是浏览器的后退按钮不再工作了。

我使用location。

I tried location。Replace—保留后退按钮,但它转到小部件被单击的页面之前的页面(它用新页面替换它)。

我如何在报告到服务器后进行页面切换,并且仍然允许后退按钮工作?

您无法返回到自动重定向的页面。这只是一个坏了的后退按钮和一个沮丧的用户。

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.

显然这行不通。它必须像这样工作:

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.

如果你想让后退按钮工作,你必须使用window.location.replace()自动重定向。