I have this code
window.onload = function() {
function foo() {
alert(\"test\");
}
setInterval(\"foo()\",500)
}
Using a string command in setInterval()
will try to look for the function in the global (window) scope, but since the function is defined in a local scope, it won't be found. You should pass the function itself to setInterval()
instead.
window.onload = function() {
function foo() {
alert("test");
}
setInterval(foo, 500);
}