Force page reload, new javascript doesn't work

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Force page reload, new javascript doesn't work

Post 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
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

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

Post by pbs »

Use Javascript

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

May this will help you
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

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

Post 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
Post Reply