jQuery: Detect Mouse Click and Open Target in New Tab

前端 未结 6 1921
暗喜
暗喜 2020-12-09 18:45

I\'m currently designing a simple forum application. It\'s mostly powered by jQuery/AJAX and loads everything on the same page; however, I know that sometimes users want to

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 19:33

    You need to also consider that ctrl-click and cmd-click are used to open new tabs (in windows/linux and mac respectively. Therefore, this would be a more complete solution:

    jQuery.isClickEventRequestingNewTab = function(clickEvent) {
        return clickEvent.metaKey || clickEvent.ctrlKey || clickEvent.which === 2;
    };
    

提交回复
热议问题