
A fun 2008 trick: a snippet (credited to Mike Cullen, featured on Dynamic Drive) that updated document.title every second so the tab showed a live clock — “TIME: 3:42:17 P.M.” visible even when the page was in a background tab.
Why the original code wouldn’t run today
The 1999-era script is a museum piece of dead patterns:
document.all— IE-only detection, meaningless since evergreen browsers wonsetTimeout("scroll()", 1000)— string-form timer evaluation (the function name also shadowedwindow.scroll)- A 12-branch
if/elsechain just to convert 24h → 12h time - HTML comment hiding (
<!-- Hide) for Netscape 2-era parsers - Globals for
hr,min,secmutated across three functions
The same effect in a dozen lines
Writing to the document title from a timer still works identically — that part of the DOM hasn’t changed. The modern version:
const baseTitle = document.title; function tick() { const now = new Date(); document.title = baseTitle + ' — ' + now.toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit', second: '2-digit' }); } tick(); setInterval(tick, 1000);
toLocaleTimeString handles the 12/24-hour question, the AM/PM suffix and zero-padding automatically using the visitor’s locale — all those if branches for free. The function-return form of setInterval avoids string evaluation entirely.
If you want full control over formatting (padded 24-hour, custom separators), reach for Intl.DateTimeFormat — build one formatter up front and call .format(now) each tick rather than re-parsing options every second.
Two practical notes
First, a per-second title update is wasted work when the tab is hidden: modern browsers throttle background-tab timers anyway, but it’s cleaner to check document.visibilityState and skip the update while hidden. Second, remember the title is also what bookmarks and screen readers announce — a title that permanently reads “TIME: 4:03:56 P.M.” is hostile to both, so restore baseTitle on pagehide or stop the timer after some idle period.
As a 2008 novelty it was neat; as a lesson it’s better than the original: the DOM API kept working for 27 years, while everything around it rotted.