I am using the code below to check when the user changes the current tab.
It works great but how can i run a jquery code insted changing the document title?
I am trying to display a box when the user leaves the current tab/page and when the user come back to see it.
<script>
var vis = (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];
}
})();
vis(function(){
document.title = vis() ? 'Visible' : 'Not visible';
//I tried
$('.alertbox').show();
});
</script>
<div class="alertbox" style="display:none;">Welcome Back</a>
check this out: http://daniemon.com/tech/webapps/page-visibility/