This answer might help.
Try giving your hyperlink an id
attribute (say, id="foo"
), and create a click handler that performs a specified action whenever a#foo
is right-clicked:
document.getElementById("foo").onmousedown = function(event) {
if (event.which == 3) {
alert('Inside Javascript Function');
}
}
EDIT:
Per your comment:
I don't want to execute the function as soon as the user right click. I want execute the function after the user right click the link and click open new tab option.
I don't believe this is possible (unless there is some arcane Chrome JavaScript API that detects such an event). It wouldn't make sense for JavaScript to know how Chrome works. Further, JavaScript is sandboxed in such a way that it doesn't have access to the user's local file system - by extension, it should not know what the Google Chrome process itself is doing.