最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to subscribe on localStorage but not on sessionStorage events - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question asked Oct 6, 2015 at 8:35 VitalyVitaly 2,6623 gold badges20 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 17

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);
发布评论

评论列表(0)

  1. 暂无评论