SessionStorage 绑定事件
SessionStorage Binding Event
类似问题来自
How do I bind event to sessionStorage?
有没有只绑定session存储而不绑定本地的呢
$(window).bind('storage', function(e)
{
alert('change');
});
上面的代码似乎绑定了两个存储(本地和会话)
我不认为将事件专门绑定到会话存储更改是可能的,但您可以忽略由 localStorage 更改引起的事件:
$(window).on('storage',function(e){
if(e.originalEvent.storageArea===sessionStorage){
alert('change');
}
// else, event is caused by an update to localStorage, ignore it
});
PS:on
是使用 jQuery.
附加事件侦听器的首选方法
类似问题来自 How do I bind event to sessionStorage?
有没有只绑定session存储而不绑定本地的呢
$(window).bind('storage', function(e)
{
alert('change');
});
上面的代码似乎绑定了两个存储(本地和会话)
我不认为将事件专门绑定到会话存储更改是可能的,但您可以忽略由 localStorage 更改引起的事件:
$(window).on('storage',function(e){
if(e.originalEvent.storageArea===sessionStorage){
alert('change');
}
// else, event is caused by an update to localStorage, ignore it
});
PS:on
是使用 jQuery.