+ 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
2 Answers
+ 2
I didn't try but maybe the following links will help you with that issue:
https://stackoverflow.com/questions/45657133/javascript-hit-counter
https://www.codementor.io/jamesezechukwu/how-to-create-a-simple-counter-using-javascript-html-css-bxcjgbbxa
+ 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