url property
Gets the address of the document that the update affects.
![]() |
Syntax
| JavaScript | |
|---|
Property values
Type: String
The document address.
Standards information
- , Section 4.4.1
Remarks
When a storage event occurs, the url and storageArea properties are set to the address and Storage object of the affected document. initStorageEvent can mimic these values, so you should not trust the values without checking the isTrusted attribute of the event.
Examples
The following code example reports the address of the storage event. It also sets the background of the output region to red if a user created the event.
<script type="text/javascript"> function createStorageEvent() { var evt = document.createEvent('StorageEvent'); evt.initStorageEvent('storage',false,false,'key','oldValue','newValue', 'http://fabrikam.com/alleged.html',window.sessionStorage); window.dispatchEvent(evt); } function reportStorage(evt) { var out = document.getElementById('output'); out.innerHTML = "Storage was updated for " + evt.url; out.style.backgroundColor = (evt.trusted ? "green" : "red"); } window.onload = function() { window.addEventListener('storage',reportStorage,false); window.sessionStorage.setItem('key','value'); } </script> <div><span id="output">[output goes here]</span></div> <button onclick="createStorageEvent()">Create a storage event</button>
See also
Show:
