Reputation: 35
Pretty much, my question is simple, and I did search for a similar question before posting this. I would like to know how to make Javascript code repeatedly execute while the page is open, rather than the code running once and being done or only responding to event handlers. I pretty much want the Javascript equivilant of:
$(document).ready(function() {
});
But I do not want to use Jquery because it is less efficient. I want to check an === condition every single frame.
Upvotes: 0
Views: 8213
Reputation: 381
Use SetInterval .. inside a window.onload function
window.onload = function() {
function test() {
alert("test");
}
setInterval(test, time_miliseconds);
}
Upvotes: 3
Reputation: 379
setInterval(function(){
var blah = whatever;
if (done){
clearInterval();
}
},time_in_milliseconds);
loop keeps looping per your milliseconds argument. If you want a loop thinner than a millisecond or as hard as the computer can do it then just a regular while(true){} will suffice.
Upvotes: 0