You are here: irt.org | FAQ | JavaScript | Misc | Q1419 [ previous next ]
The following was submitted by Padraic Renaghan
Internet Explorer 3,4,5 cache pages even when you send the HTTP headers that are supposed to indicate to the browser not to cache the page. The following page illustrates a little javascript you can use to work-around this problem.
<html> <head> <title>Page Title</title> <script language="javascript"> <!-- // this code and associated form is to workaround // a bug in Internet Explorer that will show a cached version // when the back button is used. the reload is not // triggered by Netscape since it properly never gets // the page from the cache. function onload_reloadme () { if (document.reloadme_form.reloadme_field.value == "reloadme" ) { self.location.reload(true) } else { document.reloadme_form.reloadme_field.value = "reloadme"; } // set the focus to the first non-hidden field on the second // form - the first form is always the reloadme_form below. if (document.forms[1]) { for (i=0; i<document.forms[1].elements.length; i++) { if (document.forms[1].elements[i].type.toLowerCase() != "hidden") { document.forms[1].elements[i].focus(); break; } } } } // --> </script> <!-- Yes, I know <FORM> is not proper inside <HEAD>, but it seems to work OK and avoids a blank line that most browsers put around <FORM>s. --> <form name="reloadme_form"><input type=hidden name="reloadme_field" value="dontreloadme"></form> </head> <body onLoad="onload_reloadme()"> <p>Sample Page </body> </html>