Hi, I see a lot of directories that offer to sort listings by popularity or by number of clicks. How can they know the number of clicks? I looked at the page source and the links are straight static links, no Javascript -- so how can they find out when a visitor clicks on a listing? Am I missing anything obvious?
You can't count clicks with a "straight-through" link. Maybe they're using J/S, but I'd still examine the code for funny business.
OK, so without either a redirecting link or onclick handler, you can't count clicks. http://www.deeplylinked.com/computers/hardware/ claims to count clicks (though perhaps it counts clicks on details page). The hardware page on CuteWebDirectory (just an example) and many others can sort by "Hits" or "Popularity". I see a straight-through link with no onclick handler. So what are they talking about? mad4, care to elaborate?
Yeah, good luck with counting clicks on a "straight-through link". The directory you're talking about shows 0 clicks for most links placed there three weeks ago. Not even the spiders care
Each link has an id for example id="523". There is then a script that uses getElementsByTagName and counts the number of time each element is clicked. <script>var root = ''; var a = document.getElementsByTagName("a"); for(i=0; i<a.length; i++)if(a[i].id != '') a[i].onclick = count_link; function count_link(){ i = new Image(); i.src= root+'/cl.php?id='+this.id; return true; } </script> Code (markup):
Ah, so the onclick handler is added dynamically after loading the document... I should have thought of that... Thanks!
I wouldn't say its added dynamically. Its just that each link is given a name and the script tracks each link that way rather than using an onclick for each link.
I guess it's a matter of definitions, but a.onclick = count_link; was what I meant by added dynamically.