I want to count the number of refresh of a webpage through jquery or javascript. I made research on it but did not get the perfect answer.
Can anyone help me, Please?
I want to count the number of refresh of a webpage through jquery or javascript. I made research on it but did not get the perfect answer.
Can anyone help me, Please?
var _hash = window.location.hash;
if( _hash ){
var x = parseInt( window.location.hash.replace("#", ""));
x = x+1;
window.location.hash=x;
}else{
window.location.hash = "1"
}
You can count with the help of local storage:
$(document).ready(function(){
localStorage.refresh=localStorage.refresh!=null ? localStorage.refresh : 0;
localStorage.setItem("refresh", parseInt(localStorage.refresh)+1);
alert(localStorage.refresh);
});
You can't, because you can't write to files with pure JS. However, using $('body').bind('beforeunload',function(){}) you can detect a reload, wich you could save in a cookie. But you can't count the total number of reloads on you page from all users. Also the cookie approach obviously won't work for browsers with cookies disabled.