Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9104341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:50:40+00:00 2026-06-17T01:50:40+00:00

I have various questions about setTimeout: – In my code, I clean timeouts with

  • 0

I have various questions about setTimeout:
– In my code, I clean timeouts with clearTimeout(content.idTimeout) for a particular idTiemout, but how clear all timeouts?
I have the next model:

var ContentModel = Backbone.Model.extend({
URL: "http://localhost/example.php",    
requestType: "POST",
dataType: "json",
data: "", //Set the value outside the model
idTimeout: "",  
initialize: function() {
_.bindAll(this);
},   
startSend: function (Data) { },
reply: function (Data) { 
    var dataJson = eval(Data);              
    console.log(dataJson);
    this.idTimeout = setTimeout(this.ajaxRequest(),4000);
},
problems: function (Data) {   },
ajaxRequest: function () {
    $.ajax({
        async:true,
        type: this.requestType,  dataType: this.dataType, 
        url: this.URL,  data: this.data,
        beforeSend:this.startSend,  success: this.reply,
        timeout:4000,  error:this.problems 
    });
}

And clean timeouts in the view (fragment):

initialize: function() {
    _.bindAll(this); 
    this.model = new ContentCollection();
    this.model.on("add", this.contentAdded);
        this.model.on("remove", this.removeContent);    
},
contentAdded: function(content) { //run it when add a model
    if (content.view == null) {
    var template_name = 'cam';                                                      
    content.view = new ContentView({model: content,template: $.trim($("[template='"+ template_name +"'] div").html() || "Template not found!")});
    $("div.camBox").empty();                
    content.ajaxRequest();                              
    this.$el.find(".content").find("div.camBox").append(content.view.render().el);                                              
    }                   
},  
removeContent: function(content) {
    if (content.view != null) { 
        content.view.remove();              
    }
    clearTimeout(content.idTimeout);
    content.clear();  //Clear the properties of the model   
}

– How clean a timeout when the focus is in other window and resume it when returns?
Maybe with focus method. The next code

$('html').focus(function() {
    clearTimeout(content.idTimeout);
});

in contentAdded does not work.

Edit:

http://stackoverflow.com/questions/14258596/way-to-stop-the-running-of-a-javascript-web-application-when-the-focus-is-on-oth

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:50:42+00:00Added an answer on June 17, 2026 at 1:50 am

    One solution could be:

    Specify an array for your (multiple) timeout IDs.

    window.timeouts = [];
    

    Every time you call setTimeout:

    timeouts.push(setTimeout(...));
    

    Then, if you want to stop all timeouts:

    for(var i in timeouts) {
      clearTimeout(timeouts[i]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

People have asked similar questions about the efficiency of various data structures but none
I have gone through various questions about public inner classes in this forum, however
There have been various similar questions, but they either referred to a too specific
I have 2 questions Q1: I have read about various coding indent styles like
I've checked various related questions already posted about detecting mobile devices for websites, but
I have a few questions on the various options and best practices when using
I have various HTML strings to cut to 100 characters (of the stripped content,
Through various questions I have asked here and other forums, I have come to
I have been learning about various functional languages for some time now including Haskell,
I've looked through various other questions about this and they are all fixed by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.