Reputation: 3926
In Angularjs application if user holds ctrl
then click
on hyperlink I am trying to open in new window, else it should open in the same window.
I have written the code but it only works on windows
machine and not working on MAC
i.e. safari/chrome.
Here is the below JS code
vm.goToDetails = function ($event) {
if ($event.ctrlKey || $event.keyCode == 91 || $event.keyCode == 224){
$window.open('/entry/' + vm.config.id + '/', '_blank');
} else {
$state.go('entry-details', { entryId: vm.config.id, query: vm.query });
}
}
HTML CODE
<a class="title" ng-click="$ctrl.goToDetails($event)" data-ng-bind="$ctrl.config.entryTitle"></a>
Upvotes: 1
Views: 1855
Reputation: 2111
You can try metakey for mac like this
if ($event.metaKey || $event.ctrlKey || $event.keyCode == 91 || $event.keyCode == 224) {
$window.open('/entry/' + vm.config.id + '/', '_blank');
} else {
$state.go('entry-details', { entryId: vm.config.id, query: vm.query });
}
Upvotes: 4