【问题标题】:back button not working after javascript redirectjavascript重定向后后退按钮不起作用
【发布时间】:2011-07-24 06:58:58
【问题描述】:

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

我使用 location.href 进行重定向。

我尝试了 location.replace - 它保留了后退按钮,但它会转到单击小部件的页面之前的页面(它用新页面替换它)。

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

【问题讨论】:

    标签: javascript redirect


    【解决方案1】:

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

    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() 自动重定向。

    【讨论】:

    • 不错的概念。它对我来说并不理想,因为我需要实现页面 B 并在那里发送各种信息以获取服务器端报告。由于它是一个不在我自己网站上的小部件,因此它是一个问题。但如果没有更好的选择,我可能会使用它。
    • 对我来说听起来很奇怪。您是说您必须在页面 B 中放置大量信息,但用户会自动从页面 B 重定向。我想我不明白为什么用户需要查看页面 B?
    猜你喜欢
    • 1970-01-01
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-27
    • 2014-05-06
    相关资源
    最近更新 更多