9

I have a simple request to refresh a page using a Javascript code below:

function tb_closeRefresh() {
    window.location.reload(true);
}

This works fine in IE but Firefox just gets the cached version and needs the user to press F5 to get the latest version of the page.

I have added the meta tag:

<meta http-equiv="Pragma" content="no-cache"> 

But this does not help.

Any ideas???

7 Answers7

11

you might call the same page but let it look like it is an other page by changing the querystring:

window.location.href = "index.html" + "?" + Date.parse(new Date());

This works for every browser. You could improve it by extracting the current page out of location.href.

Edit:

If you already have an existing querystring you have to use & insead of ?:

window.location.href = "product.aspx?id=prod" + "&" + Date.parse(new Date());
jantimon
  • 36,840
  • 23
  • 122
  • 185
  • +1, I was just about to post this myself. This is the method I use everytime a page needs to be reloaded through JS. – Duroth Oct 08 '09 at 10:31
  • Thanks for the response. Just tried this and it did not work. I can only assume that is because I am use URL rewriting to re-write /product_name/ to product.aspx?id=prod. But not sure? –  Oct 08 '09 at 11:00
9

If you want to refresh, you can reset window.location to window.location.

window.location = window.location

Assigning window.location will perform a redirect, and since window.location returns the current location, the statement above will act as a redirect.

August Lilleaas
  • 54,010
  • 13
  • 102
  • 111
2

try

function page_reload() 
{ 
   window.location = 'http://domain.com/page.php'; 
}

or

<a href="javascript:history.go(0);">Click here to refresh the page</a>
halocursed
  • 2,451
  • 5
  • 27
  • 34
1

I don't think Firefox supports reload, you should use:

var myUrl = window.location;
window.location.replace(myUrl)

I found that this works in IE, Apple Safari, and Firefox. It does NOT seem to work in Firefox on the Mac.

Steven Hunt
  • 2,321
  • 19
  • 18
pkane
  • 11
  • 1
0

maybe these will work?:

<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache-control" content="no-store">
Jack
  • 10,943
  • 13
  • 50
  • 65
asd
  • 1
0

You can use this code below for your issue

window.location.href = window.location.href + '?refresh';

But you need to using "Pushstate" to update the url, please see this for more details window.history.pushState refreshing the browser

Community
  • 1
  • 1
Binh LE
  • 387
  • 5
  • 17
0

The Docs say to use:

window.location.reload(true);

https://developer.mozilla.org/en-US/docs/Web/API/Location/reload

It should work in all browser including mobile.