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.

Delicja
  • 193
  • 1
  • 8
  • 18

4 Answers4

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>
Yngvar Kristiansen
  • 1,453
  • 1
  • 18
  • 25
  • How about for returning two pages and reload? – Pathros Jan 16 '17 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 http://stackoverflow.com/questions/3715047/how-to-reload-a-page-using-javascript. But I haven't tested it. – Yngvar Kristiansen Jan 18 '17 at 06:05
  • 1
    it does indeed refresh the previous page, but still keep the browser history! – Edye Chan Dec 19 '17 at 07: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.

abhinav
  • 3,199
  • 2
  • 21
  • 25
  • Is there a way to refresh page when I click back button in web browser? – Delicja May 10 '12 at 16:58
  • AFAIK not seamlessly at least, but, there is [`this`](http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript) article, which might help. – abhinav May 10 '12 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

Satya
  • 8,693
  • 5
  • 34
  • 55