Hi guys,
Im having some problem with onMouseDown event.
So like when you go to Google and click on a search result... something like this gets prefixed to the landing page:
http://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CDcQFjAB&url
My script:
$(document).ready(function () {
var count = 0;
var matchavailable = 0;
var protectedlinks = "google.com,yahoo.com";
$("a").mousedown(function () {
var linkArray = protectedlinks.split(',');
for (var i = 0; i < linkArray.length; i++) {
if ($(this).attr('href').indexOf(linkArray[i]) > 0) {
matchavailable = 1;
break;
}
else {
matchavailable = 0;
}
}
if (matchavailable == 0) {
if (count == 0) {
$(this).attr('href', "http://localhost/wordpress/redirect.php?link=" + encodeURIComponent($(this).attr('href')));
$(this).attr('target', '_blank');
count = count + 1;
}
}
});
});
This is exactly what I've been trying to do. However, with this script, the problem is -
http://localhost/wordpress/redirect.php?link=
part gets prefixed on only one link.
Suppose I have a lot of different website links like bing.com, webdeveloper.com...the thing is, if I click on bing.com I get that redirect.php prefixed. However, right after that, when I try to do it on webdeveloper.com link... nothing gets prefixed (and vica versa). What am I missing?
Hope I've been descriptive enough