按下后退按钮时强制重新加载/刷新

2022-08-30 18:57:18

我会尽力解释这一点。

我有一个应用程序,在我的页面中显示50多个项目。用户可以单击单个项目并转到页面以更新项目信息。一切正常,除了用户完成更新单个项目信息并将浏览器上的“后退”按钮点击到上一个。旧的项目信息(更新之前)仍然存在。用户必须点击刷新才能看到更新的信息。它并没有那么糟糕,但我希望提供更好的用户体验。有什么想法来解决这个问题吗?多谢。viewupdateview page


答案 1

我使用以下四行PHP代码:

// any valid date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified right now
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0");
// HTTP/1.0
header("Pragma: no-cache");

关键是使用 Cache-Control 标头的“no-store”子句。


答案 2

“fb-cache”可能真的很烦人。这里有一个简单的javascript方法:

window.onpageshow = function(evt) {
    // If persisted then it is in the page cache, force a reload of the page.
    if (evt.persisted) {
        document.body.style.display = "none";
        location.reload();
    }
};

在 Safari 6 和 IE10 中测试。


推荐