Force page reload, new javascript doesn't work
Posted: Wed May 09, 2012 5:42 am
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.
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:
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
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>
Is there (presumably there is ) a big difference between 'onLoad' and $(document).ready(function(), and is there a better way of doing this?
cheers