views:

57

answers:

3

at least in chrome, when i hit the back button, it doesn't actually reload the page, it just uses a stored copy i guess. How can i ensure that when someone does this, the page is reloaded?

A: 

If you are in the asp.net world I believe all you should need to do is

Response.Cache.SetCacheability(HttpCacheability.NoCache)

In your Page_Load

cptScarlet
+2  A: 

I haven't tried it, but you could try to send a Cache-Control HTTP header with your file. For example in PHP:

header('Cache-Control: no-cache,no-store,max-age=0');

This will tell your browsers (and caches along the way) not to cache this file under any circumstance. But delivering the previous file on clicking the back button is not necessarily considered caching and so might ignore such headers.

If you really want to avoid the back button you can try do to it with Javascript. I really don't recommend this approach - and you should step back and think about why you want to do this. That said, something like this code in your HTML body should work:

<input type="hidden" id="back_button" value="0" />
<script>
var bb = document.getElementById('back_button');
if (bb.value !== '0') {
    location.href = location.href + '?rand=' + parseInt(Math.random()*9999);
}
bb.value = '1';
</script>

This will open the current page but with a 'rand' query string parameter appended to bust any caches.

Patrice
+1  A: 

In PHP you would do this:

header('Expires: Mon, 20 Dec 1998 01:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');

However, the names of the headers sent would be the same for any server-side programming language as they all eventually go over HTTP to the client.

See Wikipedia's List of HTTP Headers for information about each of these.

sirlancelot