views:

1826

answers:

5

Hi All,

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???

A: 

This is the code, paste it in your meta tags.

< Meta Http-EQUIV=Refresh CONTENT='600; URL=index.php'>

Pay attention to the Content='600; and the URL=index.php'

those are the things you edit.

600 = the amount of seconds between refresh cycles. Change it to whatever you want.

index.php = the file you want to refresh. Change it to whatever page you want to refresh.

I have mine set to index.php to refresh my entire site every 10 minutes.

Aizaz
Sorry, I don't really understand your answer. Where do I set Content=600 or URL=index.php?My site is built using ASP.Net.Thanks
Chris
OK, just re-read and understand now. I am looking for a refresh only after an action has been performed. Not after a set time. Thanks
Chris
THEN YOU SHOULD INCLUDE ALL DETAIL IN YOUR QUESTION, I COULD NOT GUESS WHAT IS IN YOUR MIND...
Aizaz
+5  A: 

Hey,

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());
Ghommey
+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
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?
Chris
+1  A: 

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  A: 

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
I have tried this but the page does not reload at all :)
Chris
A: 

I don't think Firefox supports reload, you should use 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.

pkane