javascript 如何使用javascript重新加载上一页?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18518795/
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
How to reload previous page with javascript?
提问by Pedro Cruz
I have a website in ASP VB.NETand there's a page that goes back to the previous one when clicked, we did this with JavaScript:
我在ASP VB.NET 中有一个网站,并且有一个页面在单击时会返回到上一个页面,我们使用 JavaScript 执行此操作:
window.history.back();
But this gets you to the previous page on the state it had when going to the current page, we need it to reload, how can you do this?
但这会让您以进入当前页面时的状态进入上一页,我们需要重新加载它,你怎么能做到这一点?
回答by Suvi Vignarajah
You can't use window.history
to achieve your desired behaviour because this is not how it works. window.history
preserves the session historyof the pages visited (as stated here- it essentially mimics your browsers back/forward buttons.
你不能window.history
用来实现你想要的行为,因为这不是它的工作方式。window.history
保留会话历史记录访问过的网页(如说在这里-它基本上是模仿你的浏览器的后退/前进按钮。
As stated in the document:
如文件中所述:
There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the
location.replace()
method, which replaces the current item of the session history with the provided URL.
无法清除会话历史记录或禁用非特权代码的后退/前进导航。最接近的可用解决方案是
location.replace()
使用提供的 URL 替换会话历史记录的当前项目的方法。
So your best bet to make this work would be to use location.replace()
. You can get the previous URL of where you came from using document.referrer
.
所以你最好的办法是使用location.replace()
. 您可以使用document.referrer
.
location.replace(document.referrer);