status bar digital clock

September 16, 2008 by admin  
Filed under JavaScript

This is a JavaScript example that will display a clock in your status bar

<html>

<head>
<title></title>
<script Language="JavaScript">
var timerID = null;
var timerRunning = false;

function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}

function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."
window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock () {
stopclock();
showtime();
}
</script>
</head>

<body onLoad="startclock()">
</body>
</html>

Related posts:

  1. Add to favorites script This is an add to favorites JavaScript example. This example...
  2. Lottery number generator This example will generate random numbers which you could use...
  3. analog clock ‘timer and a picture box control Option Explicit Private Const...
  4. Capitalize letters using CSS This example shows how to use CSS to capitalize letters....
  5. Status code of a web page Status code of a web page with PHP and cURL...

Related posts brought to you by Yet Another Related Posts Plugin.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!