0

I'm actually trying to find some solution to see if the tab of the site was closed and store it on localStorage, I'm using onunload and onbeforeunload for this scenario but the problem is that if I refresh/reload (ctrl+r) or press the f5 button the value will set to true.

Matheus Lacerda
  • 5,983
  • 11
  • 29
  • 45

1 Answers1

0

You could un-set the value by determining if the page was indeed refreshed. When the site is closed, save the time at which the site was closed in local storage. When the page loads, compare the current time to the saved time and if it's "too recent", set the value to false.