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,753
  • 72
  • 57
  • 129
Manish Sapkal
  • 5,591
  • 8
  • 45
  • 74

1 Answers1

5

This is how you do it:

window.onbeforeunload = function() {
    localStorage.clear();
}
Latheesan
  • 23,247
  • 32
  • 107
  • 201
  • 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