html - Execute (javascript) code every 10 seconds but start on 0 seconds too -



html - Execute (javascript) code every 10 seconds but start on 0 seconds too -

i want execute code every 10 seconds, after first click. mean want code execute when visitor clicks anywhere on page in origin , every 10 seconds.

<!doctype html> <html> <head> </head> <body> <script type="text/javascript"> document.body.onclick= function(){ window.open('http://www.google.com', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 5, top = 5'); } </script> <input type="button" value="button" onclick=""> </body> </html>

please help me, desperately need code.

do mean this:

function dosomething() { window.open('google.com', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 5, top = 5'); } document.body.onclick=function() { document.body.onclick = null; // disable onclick dosomething(); setinterval(dosomething, 10000); }

the sec parameter setinterval time in milliseconds, why passed in 10000 (10000 milliseconds = 10 seconds).

the first parameter function want execute. can utilize anonymous function, improve passing in arguments:

setinterval(function() { dosomething(); }, 10000);

to address author's request in comments, next code open popup window when document clicked, "refresh" 5 times every 10 seconds.

var intervalcounter = 0, intervalid = 0; var intervaldelay = 10000; // time in milliseconds var popupwindow = null, popupwindowurl = "http://www.google.com"; var urlindex = 0; var urllist = [ "http://www.google.com", "http://www.youtube.com", "http://www.yahoo.com" ]; function refreshpopup() { if (popupwindow && !popupwindow.closed) { //popupwindow.location.reload(); // browsers may not allow popupwindow.location.href = popupwindowurl; } if (intervalid && (++intervalcounter) > 5) { clearinterval(intervalid); intervalcounter = 0; } } // user clicked on page somewhere document.body.onclick=function() { // if no popup window exists, create if (!popupwindow || popupwindow.closed) { urlindex = urlindex < urllist.length ? urlindex : 0; popupwindowurl = urllist[urlindex] urlindex++; popupwindow = window.open(popupwindowurl, 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 5, top = 5'); } clearinterval(intervalid); intervalid = setinterval(refreshpopup, intervaldelay); // }

javascript html timer setinterval

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -