public final class Storage extends Object
You can obtain a Storage by either invoking
getLocalStorageIfSupported()
or
getSessionStorageIfSupported()
.
Experimental API: This API is still under development and is subject to change.
If Web Storage is NOT supported in the browser, these methods return
null
.
Note: Storage events into other windows are not supported.
This may not be supported on all browsers.
Modifier and Type | Method and Description |
---|---|
static HandlerRegistration |
addStorageEventHandler(StorageEvent.Handler handler)
Registers an event handler for StorageEvents.
|
void |
clear()
Removes all items in the Storage.
|
String |
getItem(String key)
Returns the item in the Storage associated with the specified key.
|
int |
getLength()
Returns the number of items in this Storage.
|
static Storage |
getLocalStorageIfSupported()
Returns a Local Storage.
|
static Storage |
getSessionStorageIfSupported()
Returns a Session Storage.
|
static boolean |
isLocalStorageSupported()
Returns
true if the localStorage part of the
Storage API is supported on the running platform. |
static boolean |
isSessionStorageSupported()
Returns
true if the sessionStorage part of the
Storage API is supported on the running platform. |
static boolean |
isSupported()
Returns
true if the Storage API (both localStorage and
sessionStorage) is supported on the running platform. |
String |
key(int index)
Returns the key at the specified index.
|
void |
removeItem(String key)
Removes the item in the Storage associated with the specified key.
|
static void |
removeStorageEventHandler(StorageEvent.Handler handler)
De-registers an event handler for StorageEvents.
|
void |
setItem(String key,
String data)
Sets the value in the Storage associated with the specified key to the
specified data.
|
public static HandlerRegistration addStorageEventHandler(StorageEvent.Handler handler)
handler
- HandlerRegistration
used to remove this handlerpublic static Storage getLocalStorageIfSupported()
The returned storage is associated with the origin of the Document.
null
if Web Storage is
NOT supported.public static Storage getSessionStorageIfSupported()
The returned storage is associated with the current top-level browsing context.
null
if Web Storage is
NOT supported.public static boolean isLocalStorageSupported()
true
if the localStorage
part of the
Storage API is supported on the running platform.public static boolean isSessionStorageSupported()
true
if the sessionStorage
part of the
Storage API is supported on the running platform.public static boolean isSupported()
true
if the Storage API (both localStorage and
sessionStorage) is supported on the running platform.public static void removeStorageEventHandler(StorageEvent.Handler handler)
handler
- public void clear()
public String getItem(String key)
key
- the key to a value in the Storagepublic int getLength()
public String key(int index)
index
- the index of the keypublic void removeItem(String key)
key
- the key to a value in the Storagepublic void setItem(String key, String data)
key
- the key to a value in the Storagedata
- the value associated with the keyCopyright © 2018. All rights reserved.