RsD0p9BK
2/5/2016 - 4:37 AM

tabFocus.js

// How to tell if browser/tab is active

$(window).on("blur focus", function(e) {
    var prevType = $(this).data("prevType");

    if (prevType != e.type) {   //  reduce double fire issues
        switch (e.type) {
            case "blur":
                // do work
                break;
            case "focus":
                // do work
                break;
        }
    }

    $(this).data("prevType", e.type);
})

// http://stackoverflow.com/questions/1760250/how-to-tell-if-browser-tab-is-active