Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 12th Sep 2013, 11:00 AM   #1
Active Warrior
 
Join Date: 2010
Location: India
Posts: 98
Thanks: 34
Thanked 2 Times in 2 Posts
Default
onMouseDown event help
Share on: 
fb share twitter share gplus share more share

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
My script:


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;
  }
  }


  });




});
This is exactly what I've been trying to do. However, with this script, the problem is -

Code:
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, 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

roady is offline  
Unread 12th Sep 2013, 03:35 PM   #2
Web Designer
 
Join Date: 2013
Posts: 70
Thanks: 0
Thanked 19 Times in 18 Posts
Default
Re: onMouseDown event help
Share on: 
fb share twitter share gplus share more share

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;
  }
  });
});
Nathan K is offline  
Unread 13th Sep 2013, 12:47 AM   #3
digital carpenter
War Room Member
 
brutecky's Avatar
 
Join Date: 2013
Location: Pennsylvania
Posts: 1,306
Thanks: 480
Thanked 747 Times in 444 Posts
Default
Re: onMouseDown event help
Share on: 
fb share twitter share gplus share more share

Looks like your writing a script to try to jack peoples link clicks and send them to affiliate offers of yours.

brutecky is offline  
Unread 13th Sep 2013, 11:02 AM   #4
Active Warrior
 
Join Date: 2010
Location: India
Posts: 98
Thanks: 34
Thanked 2 Times in 2 Posts
Default
Re: onMouseDown event help
Share on: 
fb share twitter share gplus share more share

Yeah and its pretty much listed in the Privacy Policy/Affiliate Disclosure on my website

roady is offline  
Unread 13th Sep 2013, 12:09 PM   #5
Coder
 
BuddhaOfCode's Avatar
 
Join Date: 2013
Location: EG
Posts: 7
Thanks: 0
Thanked 2 Times in 2 Posts
Default
Re: onMouseDown event help
Share on: 
fb share twitter share gplus share more share

Evil.. Who reads TOS !!

I Code Better Than You Do!
BuddhaOfCode is offline  
The Following User Says Thank You to BuddhaOfCode For This Useful Post:
Unread 14th Sep 2013, 10:04 AM   #6
Active Warrior
 
Join Date: 2010
Location: India
Posts: 98
Thanks: 34
Thanked 2 Times in 2 Posts
Default
Re: onMouseDown event help
Share on: 
fb share twitter share gplus share more share

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!

roady is offline  
Closed Thread


Bookmarks

Tags
event, onmousedown


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 11:43 AM.