jQuery change href onhover to simulate different URL?

Sonny Forelli

Well-known member
May 8, 2008
2,330
89
48
Liberty City
Can this easily be done with something like this?

$('a').mouseover(function(){

('a').attr('href','http://www.urlshowninbrosweronmouseover (dot) com');

});


Goal would be to have aff links look (when someone mouses over) like I'm linking directly to www.merchant (dot) com but in reality have the link go to www.mytrackingplatform (dot) com and then redirect normally.


Can this be done?
 


Your going need an onclick event to, since the url will change when the user hovers over it if they click it they will be taken to the nice url.
 
here's how I did it:

Code:
<A HREF="[URL]http://mytrackingdomain.com/link.php[/URL]" onClick="this.href='http://www.mytrackingdomain.com/link.php';" onMouseOver="this.href='http://www.merchantdirectlink'; return true">THIS IS A LINK</A>

seems to work fine.

dchuk- looked at those examples before I posted, didn't work for some reason when I tried.

Any input (from anyone) on whether the above simple .js will cause any problems?
 
I usually click on links with my mouse scroller button to open them in a new tab.
In my this case your sale will not be tracked. Because browsers open the link you have specified in href="" not the one onclick="this.href=''"

There might be some combination of onMouseOver
statusbar href="" without onclick="this.href=''"
 
Code:
<a href="http://www.google.com" onmouseup="this.href='http://www.yahoo.com';">google</a>

This works fine, middle button included. tested in ie8, ff3.6 and chromedev

onclick wont work when middle button, as wmaster suggests.