I need to know about the visibility state of the tab when user does the tab switch in a particular browser and when user does the application switch.(switching out from browser)
var visibilityState,
activeTab = (function(){
var stateKey, eventKey, keys = {
hidden: "visibilitychange",
webkitHidden: "webkitvisibilitychange",
mozHidden: "mozvisibilitychange",
msHidden: "msvisibilitychange"
};
for (stateKey in keys) {
if (stateKey in document) {
eventKey = keys[stateKey];
break;
}
}
return function(c) {
if (c) document.addEventListener(eventKey, c);
return !document[stateKey];
}
})();
activeTab(function() {
visibilityState = activeTab();
});
uses
$(window).blur(function(){
if(!visibilityState){
console.log("Tab Switch happened ...");
}
});