Execute a function every millisecond
window.onload = function() {
main();
function main() {
int = setInterval('dibujar()', 100);
}
function dibujar() {
console.log('dibujando');
}
}
The script above produces an error and I think it's because of the .onload function, I need window.onload = function() {}
it because if I don't use it I get null objects from the html. If I don't use it, it works fine (I REPEAT: I need to use the function window.onload = function() {}
):
main();
function main() {
int = setInterval('dibujar()', 100);
}
function dibujar() {
console.log('dibujando');
}
I don't know why you use you
int = setInterval
can usewindow.setInterval()
and do it in the following way:Edited: You can easily do it with window.onload. You must remember that it is a function. Therefore you cannot write functions inside it. You can also store the interval in a variable to be able to access it later to stop it for example.