Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q306 Is there anyway to force the browser to reload the html page from the server and not from the browsers cache?

You are here: irt.org | FAQ | JavaScript | Redirect | Q306 [ previous next ]

<script language="JavaScript"><!--
if (document.images)
    location.reload(true); // forces a reload from the server
else
    location.href = location.href;  // just reloads the page
//--></script>

Although this will continually reload the page if it is less as shown. What is needed, is a test to see if the page has already been reloaded (perhaps in the last second):

<script language="JavaScript"><!--
function forceReload() {
    if (document.images)
        location.replace(location.href + '?' + (new Date()).getTime());
    else
        location.href = location.href + '?' + (new Date()).getTime();
}

var lastTime = location.search.substring(1) - 0;
if ((new Date()).getTime() - lastTime > 1000)
  forceReload();
//--></script>

Feedback on 'Q306 Is there anyway to force the browser to reload the html page from the server and not from the browsers cache?'

©2018 Martin Webb