simple hit counter in Javascript

Posted on 2006-04-05
Last Modified: 2008-02-01
i want a simple hit counter of my site in Javascript
i want to count every hit(refresh,etc), NOT unique visitator
Question by:fradolcino
    LVL 35

    Expert Comment

    You'd have to store the number of hits on the server...

    Otheriwse each person would just get THEIR hit count...not the number of times other people had hit the site too

    So it's probably better done with JSP/ASP/PHP/etc

    LVL 14

    Accepted Solution

    Basically, you can't have a counter without any server-side code.

    If you want to have some fun, you can try this instead:
    (save the page as index.html as the Refresh Link will redirect to index.html, or you can change the target page)

    <p id="counter">&nbsp;</p>
    <p><a href="#" onclick="refreshPage()">Refresh Page</a></p>
    <script type="text/javascript"><!--
    var num = parseInt(getQueryVariable("n"));
    if(isNaN(num)) num = 0;
    function refreshPage() {
    function getQueryVariable(variable) {
      var query =;
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return unescape(pair[1]);
      return "";

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now