Reputation: 63299
For example, if user is doing other things but not viewing this page, jquery/javascript can know?
I don't need to be very accurate, just roughly.
Upvotes: 2
Views: 444
Reputation: 235992
You might want to use a blur
or focusout
event on your document
or window
.
$(document).bind('focusout', function() {
// window or tab just lost the focus
});
that's using jQuery. You should play around with this, also use the window object as target. I'm not super sure how cross-browser this works, but it should perform well.
Upvotes: 4
Reputation: 382696
You can try this:
$(window).focus(function(){
// back in focus
});
And:
$(window).blur(function(){
// no focus
});
Upvotes: 7