检测右键单击的“在新选项卡中打开”在jQuery的链接? [英] Detect right click's "open in new tab" on link in jQuery?

查看:107
本文介绍了检测右键单击的“在新选项卡中打开”在jQuery的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的链接看起来像合法的URL,但是行为方式不一样,就像在点击事件发生时一样,定义一些跟踪URL。
当我点击鼠标左键的链接,我可以用.click()处理程序抓住它,并将href更改为别的东西。当我右键单击它不会被.click()抓住,但我可以使用.mousedown()和.mouseup(),这只是我的问题的一个部分解决方案。

I want my links to look like legit urls, but behave differently, like go to some tracking url I define, when a click event happens. When i click link with left mouse button, i can catch it with .click() handler and change the href to something else. When i right click, it won't be caught with .click(), but i can use .mousedown() and .mouseup(), which is only a partial solution to my problem.

事情是,我想确保当一些用户右键单击链接时,该链接仍然看起来是合法的,但是当他选择打开链接新的选项卡,我会抓住这个事件并更改href。最后当链接上发生实际的点击事件时,href将被更改回原来的。他们实际上去的URL,做一些事情,并将它们重定向到真正的url,但它发生得非常快。因此,此功能的目标是愚弄用户并跟踪其点击次数。 Facebook做到了,但是他们如何处理正确的点击和在新标签页中打开?

The thing is, i want to make sure that when some user right clicks the link, the link would still look legit, but when he chooses to open the link in a new tab, i would catch that event and change the href. In the end when the actual click event has happened on the link, the href would be changed back to the original. The url where they actually go, does something and redirects them to the real url, but it happens very fast. So the goal of this functionality is to fool the users and track their clicks. Facebook does it, but how do they handle the right clicks and "open in new tab"?

好的,没有任何地方没有一些代码我猜...
现在有一些代码:

Okay, not getting anywhere without some code I guess.. Some code I have right now:

    link = $(selectorName);
    var original_link = link.attr("href");
    link.click(function(){
        link.attr("href", "/track_and_redirect");
    }).mousedown(function(event) {
        switch (event.which) {
            case 3:
                //alert('Right mouse button pressed');
                link.attr("href", "/track_and_redirect");
                break;
            default:
        }
    }).mouseleave(function(){
        link.attr("href", original_link);
    });

目前,当您右键点击链接时,新的网址将显示在浏览器角落,如何我会绕过这个吗?

Currently when you right click on the link, the new url will be shown in the browser corner, how do I bypass that?

推荐答案

你不能这样做,或者你可以为你的网址做出正确的点击事件:)

You can't do this, or you can make right click event for your url :)

如何区分使用jQuery的鼠标右键单击

这篇关于检测右键单击的“在新选项卡中打开”在jQuery的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆