简体   繁体   中英

call function when users click on “open link in new tab”

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

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM