JRS: In article <11**********************@m73g2000cwd.googlegroups .com>
, dated Mon, 14 Aug 2006 07:43:47 remote, seen in
news:comp.lang.javascript,
Da**************@gmail.com posted :
>The below pasted code is my attempt to get the text of a span to change
every second.
...
setTimeout(string, 1000);
Other considerations apart, if you want it to change exactly once every
second in every browser you will need to change that second argument, to
allow for timing overheads and rounding.
See <URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI>.
PS - Are there combinations of browser and OS for which Tock() does not
always show N.1 seconds plus a varying bit, or for which Tick() does
show that?
function DP3(T) { return String(T).replace(/(\d\d\d)$/, '.$1') }
function Tick() { var D = new Date()
setTimeout("Tick()", 1000) // Drifty
DynWrite("ic", DP3(D.getTime())) }
function Tock() { var D = new Date()
setTimeout("Tock()", 1100-D%1000) // Synced
DynWrite("oc", DP3(D.getTime())) }
OP : read the newsgroup FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.