Current location: Hot Scripts Forums » General Web Coding » JavaScript » Auto Insert URL Tracking Via JavaScript...


Auto Insert URL Tracking Via JavaScript...

Reply
  #21 (permalink)  
Old 04-14-06, 05:45 AM
w2n's Avatar
w2n w2n is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
In my first try, with your last code, it is NOT working! I just cliked the link, and it opens up in a new browser window, but, the actual URL, not the URL with click tracking. I didn't right click the link and opened it in that way. Just a simple left click! Any idea, why it is not working?
__________________
SWAGATO GANGOPADHYAY
Founder/Owner/CEO
The Rozaleenda Group, Inc.


Reply With Quote
  #22 (permalink)  
Old 04-14-06, 05:47 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
The codes are identical except for the whitespacing and the line in the if-statment. That line was all I changed in the actual script.

I put the onload function there since it's much safer to run the code after the code has been completely loaded and the DOM is complete, otherwise there's a risk some links/images are not found.
Also, the code runs so fast that the user wouldn't be able to click a link before it's done.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #23 (permalink)  
Old 04-14-06, 06:01 AM
w2n's Avatar
w2n w2n is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
I have just tested again with the *exact* code you have provided in this post. It is NOT working. Is it really necessary to create a fnction (findAllLinks) and that onLoad function? Can't I put the code normall, just before the </body> tag? Anyway, it's not working anyway, so, please delete the function (replaceImgPaths) and make it (findAllLinks) work only!


Quote:
Originally Posted by TwoD
The modifications you requested, Sir. LoL
Code:
window.onload=function (){
 findAllLinks()
 replaceImgPaths()
}

function findAllLinks(){
	var exclude=["domainA.com","domainB.com"] // This is the array you modify

	var excludeRegExp=new RegExp(exclude.join("|"),"i") // This generates a regular expression based on the excluded domains.
	var links=document.getElementsByTagName('a')  // Get all the links
	for(var link=0;link<links.length;link++){
		if(!excludeRegExp.test(links[link])){ // If none of the domains in the RegExp exists in the URL, modify the link.
			links[link].onclick="window.open(\"http://url.w2n.net/*"+links[link].href+"\")"  // Prepend the clicktracker.
		}
	}
}
It now has a normal href attribute, so if the visitor right-clicks and opens it in a new window manually, it'll still work but you don't get the click tracked.
__________________
SWAGATO GANGOPADHYAY
Founder/Owner/CEO
The Rozaleenda Group, Inc.


Reply With Quote
  #24 (permalink)  
Old 04-14-06, 06:33 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, it might work if placed at the end of the document, but placing it in the header and running it onload would be the way most people would do it, and it doesn't clutter up the body contents that way.
But why is it so important that it doesn't run onload?

Yes, I alread know the code isn't working! There is something which keeps the onclick from firing at all, I don't know what yet. I thought it was working when I tested it because it popped up in a new window like it should. I didn't notice the base target tag and I was writing that response while you posted yours, so I didn't know it wasn't working at that time.

For some **** reason it won't run the code at all when it's put in as a string, I have to create a costom function instead...

Code:
var exclude=["w2n.net", "w2hub.com"] // This is the array you modify
var excludeRegExp=new RegExp(exclude.join("|"),"i") // This generates a regular expression based on the excluded domains.
var links=document.getElementsByTagName('a')  // Get all the links
for(var link=0;link<links.length;link++){
	if(!excludeRegExp.test(links[link])){ // If none of the domains in the RegExp exists in the URL, modify the link.
		links[link].onclick=new Function("window.open('http://url.w2n.net/*"+links[link].href+"');return false")
	}
}
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #25 (permalink)  
Old 04-14-06, 07:59 AM
w2n's Avatar
w2n w2n is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Hi again,

I have tested it and it IS working perfectly, as it should!

Many many thanks for the code!

:-)
__________________
SWAGATO GANGOPADHYAY
Founder/Owner/CEO
The Rozaleenda Group, Inc.


Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Auto Dealer Script nuzzle PHP 17 04-14-10 08:34 PM
Can you retrieve file list from url using Javascript? tommyb JavaScript 6 05-06-05 03:58 PM
URL Tracking Code Stripper DevilDog Script Requests 0 02-17-05 09:24 AM
Auto Insert into IE MrDarko Visual Basic 0 10-11-04 08:43 PM
javascript redirection based on referring URL andyinorbit2000 Script Requests 1 05-31-04 01:56 AM


All times are GMT -5. The time now is 11:08 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.