I am making a javascript bookmarklet that resizes all images, periodically.
javascript: function x(){
for(i=0;i<=document.getElementsByTagName('img').length;i++)
document.getElementsByTagName('img')[i].width+=1;
};
t = window.setTimeout("x()",100);
void(0);
But it runs only once. What is the problem here??
That's because setTimeout() is supposed to run only once. In order to fire an event on set intervals user setInterval() .
setTimeout() only runs once, and you said you'd like it to run every 3 minutes, and you'll want to use setInterval() for that.
2 Answers. Show activity on this post. setTimeout will only execute once.
The setTimeout function is a native JavaScript function. It sets a timer (a countdown set in milliseconds) for an execution of a callback function, calling the function upon completion of the timer.
Are you looking for setInterval()
instead of setTimeout()
by any chance?
t = window.setInterval("x()",100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With