javascript 从后退按钮访问页面时强制刷新页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9215993/
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
Force a page refresh when page visited from back button
提问by Mark_54
How can I force a page refresh of page 1 when a user returns to it from page 2 by pressing the back button? Are there vbscript or javascript approaches or is it down to set the 'no cache' somehow?
当用户通过按后退按钮从第 2 页返回到第 1 页时,如何强制刷新第 1 页?是否有 vbscript 或 javascript 方法,还是以某种方式设置“无缓存”?
回答by Diodeus - James MacFarlane
Set a cookie on page 2.
在第 2 页设置 cookie。
If the cookie is detected on page 1, reload the page.
如果在第 1 页上检测到 cookie,请重新加载该页面。
回答by Ascalonian
What about doing something like this?
做这样的事情怎么样?
<script>
if (document.referrer == "http://www.page2.html")
window.location.reload();
}
</script>
Just throw that at the top of your page 1 and this should work.
只需将其放在第 1 页的顶部,就可以了。
Update
更新
I also found a solution on the Webdeveloper.com forumsas well.