简体   繁体   English

选择“在新选项卡中打开链接”和“在新窗口中打开链接”后调用Javascript函数

[英]Calling Javascript function after selecting “Open link in new tab” and “Open link in new windw”

I want to call javascript function when user right click on link and selects "Open link in new tab" and "Open link in new windw" options. 我想在用户右键单击链接并选择“在新选项卡中打开链接”和“在新窗口中打开链接”选项时调用javascript函数。 Is there any way to do this? 有什么办法吗? I don't want to use "oncontextmenu" and also don't want to customize contextmenu options. 我不想使用“ oncontextmenu” ,也不想自定义contextmenu选项。

No , not possible. ,不可能。 You have only 2 options to capture the user's right click: 您只有两个选项可以捕获用户的右键单击:

  1. Use oncontextmenu event: 使用oncontextmenu事件:

     element.addEventListener('contextmenu', function(ev) { ev.preventDefault(); alert('success!'); return false; // standard context menu will not pop up }, false); 

OR 要么

<div oncontextmenu="javascript:alert('success!');return false;">
    Lorem Ipsum
</div>
  1. Use mousedown event: 使用mousedown事件:

     $('a').mousedown(function(ev){ if(ev.which == 3){ // 3 -> key code for right-click // do your thing alert("Right btn clicked"); } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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