javascript - Expedite a timeout function -
var timeout = settimeout(somefunction,50000); cleartimeout(timeout);
this prevent somefunction function running @ all. want while timeout running, when user clicks button, can finish countdown , execute somefunction
. possible?
as qantas 94 heavy suggested in comment, can clear timeout , run function on button press.
var timeout = settimeout(showmessage, 5000); document.getelementbyid("stop").onclick = function() { cleartimeout(timeout); showmessage(); }; function showmessage() { document.getelementbyid("output").insertadjacenthtml("afterbegin", new date() + "<br/>"); }
message displayed in 5 seconds. <input id="stop" type="button" value="display message now" /> <div id="output" />
Comments
Post a Comment