In javascript it is the opposite of that:
Code:
onload = function(){
setTimeout("alert('Cowabunga!')", 3000);
};
and:
Code:
function cow(){
alert('Cowabunga!');
}
onload = function(){
setTimeout("cow()", 3000);
};
will work, but it is not encouraged because it uses the eval engine to turn the string into code. Errors can often creep in with that, and nested quotes can become confusing to the eye.
This will also work:
Code:
function cow(){
alert('Cowabunga!');
}
onload = function(){
setTimeout(cow, 3000);
};
No quotes, and no (). But it fires with an event for cow, which can become confusing if cow can at times accept parameters. So the preferred method is:
Code:
function cow(){
alert('Cowabunga!');
}
onload = function(){
setTimeout(function(){cow();}, 3000);
};
Bookmarks