Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    link click counter

    anybody no how i can count the number of clicks on a particular link using javascript? maybe there is an easier way...

  • #2
    Regular Coder BonRouge's Avatar
    Join Date
    Mar 2006
    Location
    Sendai, Japan
    Posts
    328
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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:
    Code:
    <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:

    Code:
    <script type=text/javascript>
    var clickcounts='0';
    function count(){
    clickcounts++;
    alert(clickcounts);
    }
    </script>
    
    <a href="path/file.html" target=_blank onclick="count()">
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •