| <html> |
| <body> |
| <script> |
| // Create an iframe to receive and send storage events with. |
| var iframe = document.createElement('iframe'); |
| document.body.appendChild(iframe); |
| iframe.contentWindow.document.open(); |
| iframe.contentWindow.document.write('<body></body>'); |
| iframe.contentWindow.document.close(); |
| |
| var listener = function(event) { |
| var event_count = Number(localStorage.event_count); |
| localStorage.event_count = event_count + 1; |
| } |
| iframe.contentWindow.addEventListener('storage', listener, false); |
| localStorage.event_count = 0; |
| |
| // Print the number of events after 4 seconds. |
| setTimeout(function() { |
| console.log(localStorage.event_count); |
| }, 4000); |
| </script> |
| </body> |
| </html> |