I am building a JavaScript library. I have be working on a delay function that works like this:
function delay(ms) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > ms){
break;
}
}
}
The idea being that I can do something like this:
window.onload = function() {
delay(5000); //this function will act 5 seconds after the page loads
document.getElementById('Header').innerHTML = 'Welcome';
};
The delay works fine, but it stops all javascript on the page rather than just delaying the window.onload
function.
Does anyone know what I can do?