[英]How to reload previous page with javascript?
I have a website in ASP VB.NET and 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? 但这会让你进入上一页关于它进入当前页面时的状态,我们需要它重新加载,你怎么能这样做?
You can't use window.history
to achieve your desired behaviour because this is not how it works. 您无法使用
window.history
来实现所需的行为,因为这不是它的工作原理。 window.history
preserves the session history of the pages visited (as stated here - it essentially mimics your browsers back/forward buttons. 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()
. 因此,最好的办法是使用
location.replace()
。 You can get the previous URL of where you came from using document.referrer
. 您可以使用
document.referrer
获取您来自哪里的以前的URL。
location.replace(document.referrer);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.