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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -