1

Similar question from How do I bind event to sessionStorage?

Is there anyway to only bind the session storage only without binding the local one.

$(window).bind('storage', function(e)
{
    alert('change');
});

The code above seems to bind both storage (local and session)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
LckySnday
  • 119
  • 1
  • 1
  • 11

1 Answers1

1

I don't think binding an event exclusively to session storage changes is possible, but you could ignore events caused by changes in 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 is the preferred method for attaching event listeners with jQuery.

Ruben Serrate
  • 2,724
  • 1
  • 17
  • 21