This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

clearTimeout

Summary

Cancels a time-out that was set with the setTimeout method.

Method of dom/Windowdom/Window

Syntax

 window.clearTimeout(/* see parameter list */);

Parameters

timerID

Data-type
Number

Integer that specifies the time-out setting returned by a previous call to the setTimeout method.

Return Value

No return value

Examples

var alarm = {
  remind: function(aMessage) {
    alert(aMessage);
    delete this.timeoutID;
  },

  setup: function() {
    this.cancel();
    var self = this;
    this.timeoutID = window.setTimeout(function(msg) {self.remind(msg);}, 1000, "Wake up!");
  },

  cancel: function() {
    if(typeof this.timeoutID == "number") {
      window.clearTimeout(this.timeoutID);
      delete this.timeoutID;
    }
  }
};
window.onclick = function() { alarm.setup() };

Attributions