-2

how to calculate page refresh count in javascript using localstorage only.

I am developing one website. In that website I have to reload the page on any browser simultaneously the count will be increased. if the count equal to 6 enable popup.

Dhaarani
  • 1,350
  • 1
  • 13
  • 23

2 Answers2

5
window.addEventListener("unload", function(){
  var count = parseInt(localStorage.getItem('counter') || 0);

  localStorage.setItem('counter', ++count)
}, false);

if (localStorage.getItem('counter') == 6) {
 alert('You refreshed page 6 times')
}
ArtemKh
  • 950
  • 7
  • 15
1

I hope the below link will be help you out.

[blog] http://blogs.sitepointstatic.com/examples/tech/js-session/index.html

[blog] http://blogs.sitepointstatic.com/examples/tech/js-session/session.js