mrded mrded - 1 year ago 64
AngularJS Question

How can I catch outbound link click on an Angular 1.x website?

I'm trying to catch link clicks to external websites, to track them later.

Something like

<a href="#" ng-click="click()">foo</a>
but across all DOM tree.

Most of a content is coming from external REST server, thus I cannot use


Answer Source

what you can do is write a directve named a

angular.module('tracking', [])
.directive('a', function() {
  return {
    restrict: 'E'
    link: function(scope, element, attrs) {
      element.on('click', function() {
        if ( == outside-target)
        //your logic

important logical part would be

     if ( == outside-target)
        //your logic
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download