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.
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?