grevory / angular-local-storage

An AngularJS module that gives you access to the browsers local storage with cookie fallback
Other
2.83k stars 586 forks source link

how to share the data in multiple tabs, but also need clear after closing the browser #337

Closed hank-hong closed 7 years ago

hank-hong commented 7 years ago

Hello,

I found if I used localstorage, the data will always be saved even though I closed the browser. Buf if I use sessionstorage, the data won't be shared in multiple tabs.

Could you please give me some suggestion? Thanks

daredevil82 commented 7 years ago

You can detect the JS onunload and onbeforeunload events, and then fire a localStorageService clear call.

http://stackoverflow.com/questions/30345446/how-to-trigger-a-function-on-window-close-using-angularjs has more details for this.