Package com.google.gwt.storage.client
Class Storage
java.lang.Object
com.google.gwt.storage.client.Storage
Implements the HTML5 Storage interface.
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.
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic HandlerRegistration
Registers an event handler for StorageEvents.void
clear()
Removes all items in the Storage.Returns the item in the Storage associated with the specified key.int
Returns the number of items in this Storage.static Storage
Returns a Local Storage.static Storage
Returns a Session Storage.static boolean
Returnstrue
if thelocalStorage
part of the Storage API is supported on the running platform.static boolean
Returnstrue
if thesessionStorage
part of the Storage API is supported on the running platform.static boolean
Returnstrue
if the Storage API (both localStorage and sessionStorage) is supported on the running platform.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
De-registers an event handler for StorageEvents.void
Sets the value in the Storage associated with the specified key to the specified data.
-
Field Details
-
impl
-
-
Method Details
-
addStorageEventHandler
Registers an event handler for StorageEvents.- Parameters:
handler
-- Returns:
HandlerRegistration
used to remove this handler- See Also:
-
getLocalStorageIfSupported
Returns a Local Storage.The returned storage is associated with the origin of the Document.
- Returns:
- the localStorage instance, or
null
if Web Storage is NOT supported. - See Also:
-
getSessionStorageIfSupported
Returns a Session Storage.The returned storage is associated with the current top-level browsing context.
- Returns:
- the sessionStorage instance, or
null
if Web Storage is NOT supported. - See Also:
-
isLocalStorageSupported
public static boolean isLocalStorageSupported()Returnstrue
if thelocalStorage
part of the Storage API is supported on the running platform. -
isSessionStorageSupported
public static boolean isSessionStorageSupported()Returnstrue
if thesessionStorage
part of the Storage API is supported on the running platform. -
isSupported
public static boolean isSupported()Returnstrue
if the Storage API (both localStorage and sessionStorage) is supported on the running platform. -
removeStorageEventHandler
De-registers an event handler for StorageEvents.- Parameters:
handler
-- See Also:
-
clear
public void clear()Removes all items in the Storage.- See Also:
-
getItem
Returns the item in the Storage associated with the specified key.- Parameters:
key
- the key to a value in the Storage- Returns:
- the value associated with the given key
- See Also:
-
getLength
public int getLength()Returns the number of items in this Storage.- Returns:
- number of items in this Storage
- See Also:
-
key
Returns the key at the specified index.- Parameters:
index
- the index of the key- Returns:
- the key at the specified index in this Storage
- See Also:
-
removeItem
Removes the item in the Storage associated with the specified key.- Parameters:
key
- the key to a value in the Storage- See Also:
-
setItem
Sets the value in the Storage associated with the specified key to the specified data. Note: The empty string may not be used as a key.- Parameters:
key
- the key to a value in the Storagedata
- the value associated with the key- See Also:
-