Example
by Kiya_Iekret
HTML
<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout -->
<p>Live Example</p>
<button onclick="delayedAlert();">Show an alert box after two seconds</button>
<p></p>
<button onclick="clearAlert();">Cancel alert before it happens</button>
JavaScript
var timeoutID;
function delayedAlert() {
timeoutID = window.setTimeout(function(){orot();}, 50);
}
function clearAlert() {
window.clearTimeout(timeoutID);
}
function orot() {
return alert("That was really slow!");
}