This BLOG is not managed anymore.

How to Create Free Webpage Hit Counter using Javascript?

In this post I am gonna show you how to create your own free Webpage hit counter for your website. Many of newbies or website developer use hit counter available on internet provided by some website,But It slows down your page loading. Hit counter created using "localStorage" in javascript is far better than cookies or any ready made counter. Count will increase even if you close browser window and next time you refresh page

Copy the code given below into script tag and refresh the page to count:


if (localStorage.pagecount)
 {
 localStorage.pagecount=Number(localStorage.pagecount) +1;
 }
else
 {
 localStorage.pagecount=1;
 }
document.write("Visits: " + localStorage.pagecount + " time(s).");

If you want to count page view for session of your browsing you can use "sessionStorage". It will increase count until you close your browser.


Copy the code given below into script tag and refresh the page to count:

if (sessionStorage.clickcount)
  {
  sessionStorage.clickcount=Number(sessionStorage.clickcount)+1;
  }
else
  {
  sessionStorage.clickcount=1;
  }
document.write("You have clicked the button " + 
        sessionStorage.clickcount + " time(s) in this session."); 

Was this Information helpful?

Yes No


16 comments:

  1. Thanks a lot.
    This was very usefull information.

    :D :D :D

    ReplyDelete
  2. It's an amazing piece of writing designed for all the internet
    visitors; they will obtain advantage from it I am sure.


    Also visit my blog - Hosting Sites

    ReplyDelete
  3. great help. Thanks for sharing :)

    ReplyDelete
  4. thank you, dude!!!! you are awesome!

    ReplyDelete
  5. Thanks a lot for posting this post, Your post has always been an informative source for me.
    Industrial Timing Belt Manufacturers in india

    ReplyDelete
  6. The blog was absolutely fantastic! Lots of great information . Keep updating the blog.

    Hire Affordable Xamarin Developer
    Xamarin Developers in Frisco

    ReplyDelete
  7. As a Newbie, I am always searching online for articles that can help me. Thank you webpage

    ReplyDelete
  8. This is great! Thanks!

    ReplyDelete