As far as I understand:
window.addEventListener('storage', function(event){
...
}, false);
is subscription on both localStorage and sessionStorage events. Can I subscribe on localStorage events only?
Thanks.
A storage event is fired when you insert, update or delete a sessionStorage or localStorage property.
Why Local Storage is Insecure and You Shouldn't Use it to Store Sensitive Data. Here's the deal: most of the bad things about local storage aren't all that important. You can still get away with using it but you'll just have a slightly slower app and minor developer annoyance.
For most cases, we use the localStorage object if we want some data to be on the browser. If we want it on the server, then we use cookies, and the sessionStorage is used when we want to destroy the data whenever that specific tab gets closed or the season is closed by the user.
I don't think you can, as you say storage
is fired on the window when any storage item changes. You just have to check the storageArea
property of the event when you receive it, and ignore the ones from session storage. E.g.:
window.addEventListener('storage', function(event){
if (event.storageArea === localStorage) {
// It's local storage
}
}, false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With