【问题标题】:how can I navigate to page but ensure that the target page will be refreshed如何导航到页面但确保目标页面将被刷新
【发布时间】:2014-06-25 11:35:03
【问题描述】:

我有一个 Login.html 页面,我从中导航到我的 Main.html

现在,当我正在注销时,我想导航回 login.html,但我也想确保刷新此页面。 我不想禁用页面缓存,我只想在这个特定的场景中在刷新后导航它。

我尝试了以下操作:
window.location.replace 但它不刷新页面。
window.location.href - 也不刷新页面。
window.location.reload() - 仅刷新当前页面.

@Christof13 关于传递参数的建议是我能看到的唯一方法,但它会加载页面两次而且非常难看,

还有其他建议吗?

【问题讨论】:

  • 添加特殊标头告诉浏览器不要缓存页面stackoverflow.com/questions/49547/…
  • @christof13 谢谢,但我不想禁用页面缓存,我只想在这种特定情况下在刷新后导航它。
  • 你试过 window.location.reload(true) 吗?
  • @christof13 这将刷新当前页面,它不会将我导航到上一个页面
  • window.location.href = 怎么样?

标签: javascript jquery html refresh


【解决方案1】:

如何在注销事件上设置超时?这样,位置只会重新加载一次。

$("#myLogOutButtonOrLink").click(function() {
    setTimeout(function(){
        window.location.reload();
        }, 1000);
});

【讨论】:

    【解决方案2】:

    我的解决方案是在窗口范围内使用全局变量,如下所示:

    在 main.html 上:

    window.globals.RefreshRequired = true
    

    在 Login.html 上:

    if (window.globals && window.globals.RefreshRequired) {
                window.location.reload();
            }
    

    如果我在当前浏览器实例期间已经访问过 main.html,则通过这种方式刷新。

    【讨论】:

      猜你喜欢
      • 2021-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      • 1970-01-01
      相关资源
      最近更新 更多