Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Pausing setInterval when page/ browser is out of focus

var myInterval;
var interval_delay = 500;
var is_interval_running = false; //Optional

$(document).ready(function () {
    $(window).focus(function () {
        clearInterval(myInterval); // Clearing interval if for some reason it has not been cleared yet
        if  (!is_interval_running) //Optional
            myInterval = setInterval(interval_function, interval_delay);
    }).blur(function () {
        clearInterval(myInterval); // Clearing interval on window blur
        is_interval_running = false; //Optional
    });
});

interval_function = function () {
     is_interval_running = true; //Optional
     // Code running while window is in focus
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: like and dislike function 
Javascript :: date pretty print javascript 
Javascript :: node.js core modules 
Javascript :: javascript onclick parameters 
Javascript :: constantly send a request until a desired response is recieved expressjs 
Javascript :: select not input elements text JS 
Javascript :: javascript how to multiply numbers 
Javascript :: helperbird 
Javascript :: tableexport npm 
Javascript :: js check if field in database is true or false 
Javascript :: mreact graph 
Javascript :: add grepper code 
Javascript :: how we can use pagination in angular material and spring boot 
Javascript :: javascript llenar array con objetos 
Javascript :: template.json replacing text in files 
Javascript :: react js practical tutorial 
Javascript :: array min value in vmware_vro 
Javascript :: key html 
Javascript :: apostrophe issue in javascript 
Javascript :: how to trigger a function after stop writing in input text jquery event 
Javascript :: Scroll event throttling JS MDN 
Javascript :: c program to print triangle using recursion in javascript 
Javascript :: why typescript is superset of javascript 
Javascript :: indexable values js 
Javascript :: javascript condition based on table cell value 
Javascript :: joi validation error message in path parameter value array to string 
Javascript :: csvString to json 
Javascript :: JavaScript URL Parse including pathname 
Javascript :: javascript extrsct object 
Javascript :: check string length pixel "react" 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =