Javascript 返回并重新加载页面 - 一键

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10538585/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 01:45:39  来源:igfitidea点击:

Go back and reload page - one button

javascriptreloadbackpage-refresh

提问by Delicja

I need to go back on previous page and refresh it. I use history.go(-1) but the form on the previous page is not reloaded.

我需要返回上一页并刷新它。我使用 history.go(-1) 但上一页的表单没有重新加载。

Thanks for answers.

感谢您的回答。

回答by Yngvar Kristiansen

As per 10th June 2014, I have tested latest Chrome 35, FireFox 29 and IE 11. Only Firefox didn't do a reload when I did location.history.back(). So I replaced location.history.back() with

截至 2014 年 6 月 10 日,我已经测试了最新的 Chrome 35、FireFox 29 和 IE 11。当我执行 location.history.back() 时,只有 Firefox 没有重新加载。所以我用 location.history.back() 替换了

location.href = document.referrer

So my back button now works like this:

所以我的后退按钮现在是这样工作的:

<a href="#" onclick="location.href = document.referrer; return false;">Back</a>

回答by abhinav

If you reopen the page it should automatically refresh. You can probably get the url of the referring page via document.referrerHope that helps.

如果您重新打开页面,它应该会自动刷新。您可能可以通过document.referrerHope获得参考页面的 url,这有帮助。

回答by Satya

on the previous page use the following

在上一页使用以下内容

 <% Response.AddHeader "Pragma", "no-cache" %>
  <% Response.Expires = -1 %>

in case of asp

在asp的情况下

in addition check this

另外检查这个

回答by Yucel Daglar

I think I invented a way of doing this. By adding a random parameter to url, we force browser to refresh...

我想我发明了一种方法来做到这一点。通过向 url 添加随机参数,我们强制浏览器刷新...

var backLocation = document.referrer;
if (backLocation) {
    if (backLocation.indexOf("?") > -1) {
        backLocation += "&randomParam=" + new Date().getTime();
    } else {
        backLocation += "?randomParam=" + new Date().getTime();
    }
    window.location.assign(backLocation);
}