I'm surprised both functions get invoked in any browser. But you might have better luck with something like:
function foo() {
// javascript code
setTimeout(bar, additionalDelay);
}
function bar() {
// javascript code
}
window.onload = function() { setTimeout(foo, delay); };
Edit: Nevermind, I see why both of the timeouts execute. When you do something like:
window.onload = setTimeout(bar, delay);
...you are not actually setting window.onload
to execute your function after a delay. Instead this is immediately invoking setTimeout()
to schedule your function call, and assigning the result (a handle to the scheduled function invocation) to window.onload
. This is not correct, and will probably cause a runtime error in some browsers when they try to invoke window.onload
as a function.
What you want to do instead is assign a function to window.onload
, like:
window.onload = function() {
setTimeout(foo, delay);
setTimeout(bar, delay);
};
var arr = [];
andarr.push(a); arr.push(b);
it'll be perfect :) – Miliaria