Exec21
Exec21

Reputation: 827

Javascript global (body) click event registration is not working in Safari

Android and Chrome events work fine, try the following options:

$window.onclick = function () {
   if ($scope.accountsMenuOpen) {
       $scope.accountsMenuOpen = false;
       $scope.$apply();
   }
};

document.body.addEventListener('click', function () {
  if ($scope.accountsMenuOpen) {
       $scope.accountsMenuOpen = false;
       $scope.$apply();
   }
});

document.querySelector('body').addEventListener('click', function () {
   if ($scope.accountsMenuOpen) {
       $scope.accountsMenuOpen = false;
       $scope.$apply();
   }
});

I double check and Javascript is enabled in Safari; also try with the following angularjs directive:

<body click-capture>

I just debug in Safari and click event is triggered in some elements (where elements are in a ng-controller context). I don't know why is not registered in all body elements.

Upvotes: 0

Views: 194

Answers (1)

Exec21
Exec21

Reputation: 827

After digging more into touch events there is one available in safari, thanks Carcigenicate for the hint

document.body.addEventListener('touchend', function () {   
  if ($scope.accountsMenuOpen) {
     $scope.accountsMenuOpen = false;
     $scope.$apply();
  }
});

Upvotes: 1

Related Questions