Page views counter in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Page views counter in JavaScript

Plse help me i have a blog i need show user how many views in my blog so i need JavaScript code for that help me plse

21st Oct 2018, 10:48 AM
Programmer Raja
Programmer Raja - avatar
2 Answers
21st Oct 2018, 11:17 AM
Mirko Klotzsche
Mirko Klotzsche - avatar
+ 1
rough idea create a function in php/ruby/java/(anything you use at server) file, to handle a count request where it need to take the client ip (if you want the count to be unique). inside check if the last updated data are still valid(if you want to refesh the count every day/month) then update your data (at database or json or anything) and increase the viewcount by 1, for unique count just store the ip if its not in the database yet. now send back the viewcount/total ip. at the client side write a function that run on page load, write an xmlhttprequest and send a viewcount request to your serverside file for the update, once the view count are sent back use it to update your html element using dom
21st Oct 2018, 12:25 PM
Taste
Taste - avatar