Answers for "how to check if browser tab is active javascript"

6

how to check if browser tab is active javascript

let browser_active = ((typeof document.hasFocus != 'undefined' ? document.hasFocus() : 1) ? 1 : 0);
if (!browser_active) {
 // active
}
Posted by: Guest on April-08-2022
-1

javascript detect if the browser tab is active

var interval_id;
$(window).focus(function() {
    if (!interval_id)
        interval_id = setInterval(hard_work, 1000);
});

$(window).blur(function() {
    clearInterval(interval_id);
    interval_id = 0;
});
Posted by: Guest on April-29-2020

Code answers related to "how to check if browser tab is active javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language