Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Firefox to Reload Page on Back Button

Tags:

How do you make Firefox rerun javascript and reload the entire page when the user presses the back button? I was able to do this in all browsers except Firefox from the help of another SO question by adding this code:

history.navigationMode = 'compatible';
$("body").unload(function(){})

And also adding an iFrame... But this doesn't work in Firefox. Is there anything to do?

like image 897
Lance Avatar asked Aug 21 '10 07:08

Lance


People also ask

How do I force Firefox to refresh?

Firefox and Windows: To hard refresh on Firefox on Windows, there are also two easy hotkey commands you can use: Hold down Ctrl, Shift and the 'R' key. Or Hold down Ctrl and press F5.

How do I enable Auto Reload in Firefox?

Disable Auto-Refresh in Firefox Just type about:config into the Firefox address bar, “Accept the risks” involved in making changes to Firefox, then near the top of the list, you should see the preference called accessibility. blockautorefresh .

Why is the back button not working in Firefox?

Clear Browser Cache and Cookies If clicking or tapping the Back button doesn't do anything or causes the same page to reload, clearing it might help fix things.


2 Answers

add this between your HEAD tags

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
like image 73
jknair Avatar answered Sep 28 '22 05:09

jknair


In my case, after the final user Post his new data to server, he is redirected to another page. But when the final user press the back button, the form is pre-populated with the old data. So, reload page is needed.

I did a workaround for Firefox and another for Google Chrome. They have different behavior to show cached pages.

Doing this will prevent Firefox to cache the page and the back button will bring the page from server.

window.onunload = function(){};

But Google Chrome do it in another way and the solution above did not work for me. So I did another workaround for Chrome. I did a flag that mark the form as dirty.

At the top of <head>, before load anything, I check the cookie

if(document.cookie.match(/my-form=dirty/)) {
  document.cookie = "my-form=; expires=-1; path="+document.location.pathname;
  window.location.reload();
}

With a help of jQuery, I write the cookie when user modify something

$(document).load(function(){
  $(':input').change(function(){
    document.cookie = "my-form=dirty; expires=86400000; path="+document.location.pathname;
  })
})

Good to know:

  • http://code.google.com/p/chromium/issues/detail?id=2636
  • https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching
like image 33
Fabio Montefuscolo Avatar answered Sep 28 '22 04:09

Fabio Montefuscolo