title: How can I get an event to fire every time localStorage is updated in Safari 5+?
body: <p>I have tried to follow <a href="https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/Name-ValueStorage/Name-ValueStorage.html#//apple_ref/doc/uid/TP40007256-CH6-SW6" rel="nofollow noreferrer">the examples on the Safari Developer Site</a>.</p>
  
  <p>The documentation suggests adding an event listener like so:</p>
  
  <pre><code>window.addEventListener('storage', storage_handler, false);
  </code></pre>
  
  <p>And then setting your handler function like this:</p>
  
  <pre><code>function storage_handler(evt)
  {
      alert('The modified key was '+evt.key);
      alert('The original value was '+evt.oldValue);
      alert('The new value is '+evt.newValue);
      alert('The URL of the page that made the change was '+evt.url);
      alert('The window where the change was made was '+evt.source);
  }
  </code></pre>
  
  <p>But I can't seem to get this code to work on my machine (OS X 10.6, Safari 5.01) nor on Safari on my iPhone 3GS (iOS 4.02).</p>
  
  <p><a href="http://www.ibm.com/developerworks/xml/library/x-html5mobile2/" rel="nofollow noreferrer">This article</a> offers a separate method:</p>
  
  <pre><code>window.onload = function() {
      ...
      document.body.setAttribute("onstorage", "handleOnStorage();");
  }
  
  function handleOnStorage() {
      if (window.event &amp;&amp; window.event.key.indexOf("index::") == 0){
          $("stats").innerHTML = "";
          displayStats();
      }
  }
  </code></pre>
  
  <p>But I haven't had any luck with that either.</p>
  
  <p>Am I doing something wrong? Is this a bug?</p>