| | #1 |
| Active Warrior Join Date: 2010 Location: India
Posts: 98
Thanks: 34
Thanked 2 Times in 2 Posts
|
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: Code: http://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CDcQFjAB&url Code: $(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;
}
}
});
}); Code: http://localhost/wordpress/redirect.php?link= Suppose I have a lot of different website links like bing.com, warriorforum.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 warriorforum .com link... nothing gets prefixed (and vica versa). What am I missing? Hope I've been descriptive enough |
| | |
| |
| | #2 |
| Web Designer Join Date: 2013
Posts: 70
Thanks: 0
Thanked 19 Times in 18 Posts
|
Its only working on one link because of the count variable. Initially it is set to 0 but after you click a link the value of the count variable is incremented by 1. If you click a link again the condition count == 0 is not met. To solve this remove the condition or change it. Code: $(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) {
$(this).attr('href', "http://localhost/wordpress/redirect.php?link=" + encodeURIComponent($(this).attr('href')));
$(this).attr('target', '_blank');
count = count + 1;
}
});
}); |
| |
| | #3 |
| digital carpenter War Room Member Join Date: 2013 Location: Pennsylvania
Posts: 1,306
Thanks: 480
Thanked 747 Times in 444 Posts
|
Looks like your writing a script to try to jack peoples link clicks and send them to affiliate offers of yours.
|
| | |
| |
| | #4 |
| Active Warrior Join Date: 2010 Location: India
Posts: 98
Thanks: 34
Thanked 2 Times in 2 Posts
|
Yeah and its pretty much listed in the Privacy Policy/Affiliate Disclosure on my website |
| | |
| |
| | #6 |
| Active Warrior Join Date: 2010 Location: India
Posts: 98
Thanks: 34
Thanked 2 Times in 2 Posts
|
Actually, it's not just affiliate links. Moreover, my main priority is to track the clicks using a semi-proprietary software. Anyway, thanks for the help!
|
| | |
| |
|
| Bookmarks |
| Tags |
| event, onmousedown |
| |