initStorageEvent method
Initializes a new Document Object Model (DOM) storage event that the createEvent method created.
![]() |
Syntax
var retval = StorageEvent.initStorageEvent(eventType, canBubble, cancelable, keyArg, oldValueArg, newValueArg, urlArg, storageAreaArg);Parameters
- eventType [in]
-
Type: String
The following value, or a user-defined custom event type:
-
An onstorage event.
- canBubble [in]
-
Type: Boolean
- cancelable [in]
-
Type: Boolean
- keyArg [in]
-
Type: String
The storage key. This value is returned in the key attribute of the event.
- oldValueArg [in]
-
Type: String
The previous value of the storage key, or null. This value is returned in the oldValue attribute of the event.
- newValueArg [in]
-
Type: String
The new value of the storage key, or null. This value is returned in the newValue attribute of the event.
- urlArg [in]
-
Type: String
The address of the document that is processing the event. This value is returned in the url attribute of the event.
- storageAreaArg [in]
-
Type: IHTMLStorage
The Storage object that is modified. This value is returned in the storageArea attribute of the event.
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Standards information
- , Section 4.4.1
Examples
The following code example demonstrates how to create and dispatch a custom storage 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) { alert("Storage was updated for " + evt.url); } window.onload = function() { window.addEventListener('storage',reportStorage,false); } </script> <button onclick="createStorageEvent()">Create a storage event</button>
See also
