<!DOCTYPE html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>
<head>
<title>gibbs.com Toggleable Refresh Example</title>
<script language="JavaScript">
// The following variable must be set to 1; if we start with 0 // clicking on the checkbox simply forces a single refresh
var RefreshEnabled = 1;
// This variable specifies the refresh interval in milliseconds
var RefreshInterval = 5000;
// The JavaScript setTimeout method defines the function to // be called each time the specified period elapses.
window.setTimeout("DoRefresh()", RefreshInterval);
function DoRefresh() { if (RefreshEnabled == 1) {window.location = window.location.pathname+window.location.search;}
// Let’s assume this page was generated by the URL: // // http://www.somesite.com/demos/refresh.html?update // // The property window.location.pathname will be “demos/refresh.html” // and the property location.search will be the URL tail (the data sent // if the page involves a GET request). Thus the location.search property // for the URL above would be ?update. By setting the property // window.location to the combined value of these two existing properties // we force the given page to be loaded from the default domain // (“www.somesite.com”) using the default access method (“http:”). }
function ToggleRefresh() { if (RefreshEnabled == 1) {RefreshEnabled = 0;} else { RefreshEnabled = 1; DoRefresh(); } }
</script>
</head>
<body>
<script>
// START TEST CONTENT. // The following code simply gives this example something to display // remove everything from here to “END TEST CONTENT.” unless you want to // include an updating display of local time.
DTG = new Date();
var Hours; var Mins; var Secs; var Time;
Hours = DTG.getHours(); Mins = DTG.getMinutes(); Secs = DTG.getSeconds();
if (Hours >= 12) { Time = " PM"; } else { Time = " AM"; } if (Hours > 12) { Hours = Hours - 12; } if (Hours == 0) { Hours = 12; } if (Mins < 10) { Mins = "0" + Mins; } if (Secs < 10) { Secs = "0" + Secs; }
document.write("<b>Time:</b> " + Hours + ":" + Mins + ":" + Secs + " " + Time );
// END TEST CONTENT.
</script>
<!-- The following checkbox generates a call to the function that toggles the autorefresh state when it is clicked. -->
<input checked type="checkbox" onclick="ToggleRefresh()"> Check to autorefresh.
</body>
</html>