简体   繁体   English

是否可以使用javascript捕获“在新标签中打开”单击上下文菜单的事件?

[英]Is it possible to capture “Open in New Tab” clicked event of context menu using javascript?

I know I can use capture the Right Click event by using jQuery's " contextmenu " but my question is, how can I capture the event after the context menu appears ie When the user clicks on "Open Link in New Tab" action. 我知道我可以通过使用jQuery的“ contextmenu ”来捕获右键单击事件,但我的问题是,如何在上下文菜单出现后捕获事件,即当用户点击“在新标签中打开链接”操作时。

Any help? 有帮助吗?

Thanks. 谢谢。

在此输入图像描述

I found this solution 我找到了这个解决方案

<script type='text/javascript'>
jQuery(function($){
    $('a').mousedown(function(event) {
        switch (event.which) {
            case 1:
                //alert('Left mouse button pressed');
                $(this).attr('target','_self');
                break;
            case 2:
                //alert('Middle mouse button pressed');
                $(this).attr('target','_blank');
                break;
            case 3:
                //alert('Right mouse button pressed');
                $(this).attr('target','_blank');
                break;
            default:
                //alert('You have a strange mouse');
                $(this).attr('target','_self"');
        }
    });
});

Here jQuery: Detect Mouse Click and Open Target in New Tab 这里是jQuery:在新标签中检测鼠标单击并打开目标

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

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