I've tried about 10 different ways that I found on here and the only found one that works close. I'm having an issue with Hostgator all of a sudden not displaying new content on php pages that access and display data from text files and/or databases. These pages have been in place for years working fine and continue to do so on other hosts. The only problem I have with the script below is that it won't refresh the page on the first visit. After the first refresh it will then show changes. I need something that will refresh all the time regardless of a visitors history or browser settings.
<script type='text/javascript'>
(function()
{
if( window.localStorage ) {
if( !localStorage.getItem( 'firstLoad' ) ) {
localStorage[ 'firstLoad' ] = true;
window.location.reload();
}
else
localStorage.removeItem( 'firstLoad' );
}
})();
</script>
you can use a cookie:
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
(function()
{
var value = readCookie('mycookiereload');
if(value == null)
{
var date = new Date();
date.setTime(date.getTime()+(3600000));
var expires = "; expires="+date.toGMTString();
document.cookie = "mycookiereload=1"+expires+"; path=/";
alert("going to reload");
window.location.reload();
}
else
{
var date = new Date();
date.setTime(date.getTime()-(3600000));
var expires = "; expires="+date.toGMTString();
document.cookie = "mycookiereload="+expires+"; path=/";
alert("kill cookie");
}
})();
this will reload the page once. everytime you visit a page, it checks the cookie, if it's not there, creates and reloads, if it's there, removes the cookie to get the same effect again.