0

I am using Angularjs. In my application i have one link say(opentab).I have added ng-click event on this

<a href="javascript:void(0);" ng-click="clickevent()">opentab</a> 

I want when users right click on "opentab" and select "open link in new tab" it call clickevent function

Thanks

user3106347
  • 639
  • 2
  • 10
  • 27
  • What is your expected behaviour? If it is to detect all cases of user trying to open link in new tab, just checking for click or even contextmenu events won't be enough. User could use shortcut keys to open link on new tab or even configure his browser for that. And i don't think it would be that easy to catch all possible cases – A. Wolff Jun 02 '16 at 08:19
  • right now i am looking for only open link in new tab by right click only – user3106347 Jun 02 '16 at 08:20
  • see this http://stackoverflow.com/questions/15731634/how-do-i-handle-right-click-events-in-angular-js – Hadi J Jun 02 '16 at 08:21

1 Answers1

1

You can not detect that, but you can detect the ctrl + click, cmd + click etc. something like this.

HTML

<div ng-app="myApp" ng-controller="mainController">
  <a href="javascript:void(0);" href="javascript:void(0);" ng-click="clickevent($event)">Opentab</a> 
</div>

JS

var app = angular.module("myApp", []);
  app.controller("mainController", function($scope) {
        $scope.clickevent = function($event){
          if (event.ctrlKey || event.shiftKey || event.metaKey || $event.which == 2) {
            alert("aa");
          }

        }
    });

Hope it help, Cheers :)

Vaibhav Jain
  • 687
  • 4
  • 15