4

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.

Thanks for answers.

1
  • Why not just link to the other page? Commented May 10, 2012 at 16:48

4 Answers 4

10

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

location.href = document.referrer

So my back button now works like this:

<a href="#" onclick="location.href = document.referrer; return false;">Back</a>
3
  • How about for returning two pages and reload?
    – Pathros
    Commented Jan 16, 2017 at 21:42
  • @Pathros Not possible with this method, as document.referrer is only one page back. One idea that comes to mind is using location.history.back(); location.history.back(); and then a solution from stackoverflow.com/questions/3715047/…. But I haven't tested it. Commented Jan 18, 2017 at 6:05
  • 1
    it does indeed refresh the previous page, but still keep the browser history!
    – Edye Chan
    Commented Dec 19, 2017 at 7:37
5

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

2
  • Is there a way to refresh page when I click back button in web browser?
    – Delicja
    Commented May 10, 2012 at 16:58
  • AFAIK not seamlessly at least, but, there is this article, which might help.
    – abhinav
    Commented May 10, 2012 at 17:12
1

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

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);
}
0

on the previous page use the following

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

in case of asp

in addition check this

1
  • look at the link that I gave , it has multiple combos for different languages
    – Satya
    Commented May 10, 2012 at 16:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.