检测外部链接点击?

Ard*_*aba 2 javascript jquery

如何检测外部链接点击?

我有一个简单的问题,可能有也可能没有简单的答案.我需要检测我的某些网页用户是否点击了外部链接,例如广告.

我的第一个想法是,我会在特定链接上放置一个随机数量的透明div,这样用户就可以点击它直到他被重定向到新页面,但这对用户来说是不可取的,并且仍然可以被利用.

我希望你们可以帮助我,我会尽我所能帮助你们.

抱歉我的英语,因为我的母语不是英语.

gui*_*ido 5

使用jquery,选择所有外部链接和click事件的处理程序:

// Creating custom :external selector
$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname);
};

// Manage clicks on external links
$('a:external').click(function() {
    // do your stuff here, ie send the link href to some server-side script
    $.ajax({ type: "POST", url: "some.php", data: "href="+$(this).attr("href") });
});