Skip to content

Instantly share code, notes, and snippets.

@velenux
Created July 18, 2010 19:33
Show Gist options
  • Save velenux/480644 to your computer and use it in GitHub Desktop.
Save velenux/480644 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Simple javascript timed output</title>
<script language="Javascript">
var delay = 1000; // 1 second delay
function writeOut() {
// get content via xml http request or whatever
var out = getContent();
// get our target div
t = document.getElementById('target');
// set the target div content to the content itself
// PLUS a line break PLUS our output
t.innerHTML = t.innerHTML + '<br>' + out;
// call back itself in 1 sec
setTimeout('writeOut()', delay);
}
function getContent() {
// some meaningless content
return Math.floor(Math.random()*11);
}
</script>
</head>
<body onLoad="writeOut();">
<div id="target">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment