javascript - $window.onblur randomly stops working -


I am still running safari and not always is working in Chrome: / P>

  app.controller (.... function ($ window) {$ window.focus (); $ window.onfocus = function () {$ scope.inFocus = true;}; $ window .onblur = function () {console.log ("onblur"); $ scope.inFocus = false;};});  

console.log is not always triggered. I was thinking that this was a bug or was I doing something wrong?

UPDATE: I tried the solution given by @Gebe, it is still breaking down sometimes, I am thinking that another action is interfering with it. It looks random though ...

Update 2: I still do not know how it got trapped, but I know how to remove it:

  1. I click on window input to focus it.
  2. I click outside of the input to focus.
  3. I switch tabs and come back. It works again.

Instead of using the API for angular.element Try

  angular.liment ($ window) .bind ('blurred', function () {console.log ("onblur"); $ scope.inFocus = false;}) ;  


Comments