[英]$window.onblur randomly stops working
I have it running fine on safari right now and not always working in chrome: 我现在可以在Safari上正常运行,并且不能始终在chrome中运行:
app.controller(.... function($window){
$window.focus();
$window.onfocus = function(){
$scope.inFocus = true;
};
$window.onblur = function (){
console.log("onblur");
$scope.inFocus = false;
};
});
The console.log is not always triggered. console.log并非总是被触发。 I was wondering if that was a bug or something I am doing wrong? 我想知道那是一个错误还是我做错了什么?
Update: I tried the solution given by @Gabe. 更新:我尝试了@Gabe给出的解决方案。 It is still breaking sometimes, I am wondering if another action is interfering with it. 有时它仍在中断,我想知道是否有其他动作正在干扰它。 It does look random though... 它看起来确实是随机的...
Update 2: I still don't know how it gets stuck, but I know how to get it unstuck: 更新2:我仍然不知道它如何卡住,但我知道如何使其不卡住:
Try using the API for angular.element
instead 尝试改用API作为angular.element
angular.element($window).bind('blur', function (){
console.log("onblur");
$scope.inFocus = false;
});
http://plnkr.co/edit/khYHeJlvn2uCzKeTjndM http://plnkr.co/edit/khYHeJlvn2uCzKeTjndM
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.