0

How do I clear local storage when my website is closed in all the tabs in a browser? means If my user is open my website in multiple tabs, and when user is close browser or close tabs one by one, I need to clear local storage on last tab close event (e.g. on beforeunload event).

Does anybody have idea to do this?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Manish Sapkal
  • 4,953
  • 7
  • 42
  • 71

1 Answers1

5

This is how you do it:

window.onbeforeunload = function() {
    localStorage.clear();
}
Latheesan
  • 21,527
  • 27
  • 96
  • 188
  • that I already doing. but it should happen only when browser is going to close or last tab of my app is going to close. – Manish Sapkal Jun 26 '14 at 09:30