运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Storage Event</h1> <p>The Storage Event is triggered when there is a change in the window's storage area.</p> <p><strong>Note:</strong> The storage event is only triggered when a window <strong>other than itself</strong> makes the changes.</p> <p>Therefore, in this example, a hidden iframe is used. The hidden iframe has one mission; whenever it is targeted, it will change the value of a local storage item named "mytime" with the value of the current date in milliseconds.</p> <h1>The url Property</h1> <p>The url property belongs to the Storage Event object, and returns the url of the page where the item was changed.</p> <p>The url of the page where the item was changed:</p> <p id="demo"></p> <script> window.addEventListener("storage", myFunction); function myFunction(event) { x = event.url; document.getElementById("demo").innerHTML = x; } </script> <iframe src="test_local_storage.htm" style="display:none"></iframe> </body> </html>