...

View Full Version : link click counter



PGMR_1998
04-30-2007, 04:34 PM
anybody no how i can count the number of clicks on a particular link using javascript? maybe there is an easier way...

BonRouge
04-30-2007, 04:46 PM
You won't be able to do it with just javascript (as far as I'm aware) - you'll need a server-side language too.

brandonH
04-30-2007, 06:41 PM
well you can count how many times the user clicks on anything, so long as the windows location doesnt change. so, if you are using links that dont go anywhere, or links that target a new window, you can count all day long. but if the link changes the location value of the window, no such luck, you would need server side script as BonRogue stated above.


this will work as long as the link doesnt do anything:


<script type=text/javascript>
var clickcounts='0';
function count(){
clickcounts++;
alert(clickcounts);
}
</script>

<a href="javascript:count();">count clicks</a>




this will owrk if the link targets a new window:



<script type=text/javascript>
var clickcounts='0';
function count(){
clickcounts++;
alert(clickcounts);
}
</script>

<a href="path/file.html" target=_blank onclick="count()">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum