Reputation: 2143
I'd like to check if the user is currently viewing the browser tab, like if you are at google chrome and you have facebook, twitter and the application, and you want to know if the application is selected between all 3. Is there a way to do it with purely with angular or do I need to do something like this:
$(window).focus(function() {
console.log('enter');
}).blur(function() {
console.log('out');
});
Upvotes: 0
Views: 2499
Reputation: 77956
AngularJS comes bundled with JQLite (subset of jQuery). You can inject the mock $window
to keep it testable or just use window
. Your call :
angular.element($window).bind('focus', function() {
console.log('enter');
}).bind('blur', function() {
console.log('out');
});
Upvotes: 3