javascript 浏览器后退按钮显示缓存中的页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20088616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Browser back button showing the page from cache?
提问by Nauphal
When I logout from wordpress website, it will be redirected to the login page. But the issue is, if I hit the browser back button, It will show the previous page, which need the authorization. I know, the page is being loaded from the browser cache and no interaction with the server is happening. But I need to force the page to reload if the user hit the browser back button.
当我从 wordpress 网站注销时,它将被重定向到登录页面。但问题是,如果我点击浏览器的后退按钮,它会显示需要授权的上一页。我知道,页面是从浏览器缓存加载的,并且没有与服务器进行交互。但是如果用户点击浏览器后退按钮,我需要强制页面重新加载。
I did check the header and I could find the following
我确实检查了标题,我可以找到以下内容
Cache-Control: no-cache, must-revalidate, max-age=0
I have also tried by adding the following meta tags and it didn't work.
我也尝试过添加以下元标记,但没有用。
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
Please help
请帮忙
回答by Nauphal
I have tried by setting header like below and it worked like a charm!
我已经尝试过设置像下面这样的标题,它就像一个魅力!
header("Cache-Control: private, must-revalidate,
max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
);
回答by Renosh
Tried lot of solutions but only the below one worked out . Added below java script in the logout page. All the other solutions will work fine in browsers other than IE.
尝试了很多解决方案,但只有以下一个解决了。在注销页面中添加了以下 java 脚本。所有其他解决方案在 IE 以外的浏览器中都可以正常工作。
window.onunload = function() {
window.location.href = "<%=request.getContextPath()%>/logout.jsp";
};