Page 1 of 1

Force page reload, new javascript doesn't work

Posted: Wed May 09, 2012 5:42 am
by IGGt
I have a page that reloads every 60 seconds. Periodically though, it just hangs.

Previously I used the following javascript to check if the page had refreshed after 180 seconds, and if not forces a refresh, clears all my PHP variables and SESSION data.

Code: Select all

//n.b. timeout = 0 is for when the page is configured to not reload automatically every 60 seconds (manual refresh only)			
function goToSessionDestroy()
	{
		window.location = "system.SessionDestroy.php";
	}

function RefreshWarning(timeOut) 
	{
		var u=setTimeout("goToSessionDestroy()",timeOut);
	}

function onLoadFunctions(timeOut)
	{
		if (timeOut != 0){RefreshWarning(timeOut);};
	}

<html>
<body onload="onLoadFunctions(<?php print $warnRefresh; ?>)" >

This seems to work just fine. since then however, I have been reading a bit more about javascript and was told that it was potentially bad practice to use onload events as they can be couteracted by onload events in other pages that are 'included' (and I have quite a lot of pages that are 'included'). So I rewrote my javascript as follows:

Code: Select all

<script language='Javascript'>
$(document).ready(function() 
  {
    var timeout = <?php print $warnRefresh; ?>;
    $('#alertBox').hide();
    if (timeout >= 1)  
      {  
        $('#alertBox').delay(timeout).fadeIn(1, function() 
          {
            window.location = 'system.SessionDestroy.php';  
          }
        );
      }
  }
);
</script>
But this doesn't work. when the page hangs, nothing happens, and the javascript doesn't fire.

Is there (presumably there is ) a big difference between 'onLoad' and $(document).ready(function(), and is there a better way of doing this?


cheers

Re: Force page reload, new javascript doesn't work

Posted: Wed May 09, 2012 5:59 am
by pbs
Use Javascript

setInterval(function() {window.location.reload();},60000);

May this will help you

Re: Force page reload, new javascript doesn't work

Posted: Wed May 09, 2012 9:51 am
by IGGt
thanks, but that is already what I use to reload the page.

I think I have narrowed it down to

Code: Select all

window.location = 'system.SessionDestroy.php';
As the #Alertbox (a table that is changed from 'hide' to 'block' after 180 seconds) appears, but the page isn't refreshed / forwarded / replaced with the system.SessionDestroy.php page