nsIDOMStorage 编辑

dom/interfaces/storage/nsIDOMStorage.idlScriptable This interface represents the storage space used for session storage in the DOM. Items stored in session storage may be accessed by any interested party in the same browsing context. 1.0 66 Introduced Gecko 1.8.1 Inherits from: nsISupports Last changed in Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)

A DOM window's session storage object can be retrieved from the window's sessionStorage attribute.

A storage object stores an arbitrary set of key-value pairs, which may be retrieved, modified and removed as needed. A key may only exist once within a storage object, and only one value may be associated with a particular key. Keys are stored in a particular order with the condition that this order not change by merely changing the value associated with a key, but the order may change when a key is added or removed.

Method overview

void clear();
DOMString getItem(in DOMString key);
DOMString key(in unsigned long index);
void removeItem(in DOMString key);
void setItem(in DOMString key, in DOMString data);

Attributes

AttributeTypeDescription
lengthunsigned longThe number of keys stored in the session store. Read only.

Methods

clear()

Clear the content of this storage bound to a domain or an origin.

void clear();
Parameters

None.

getItem()

Returns from session storage the data corresponding to the specified key.

DOMString getItem(
  in DOMString key
);
Parameters
key
The key for which data should be returned.
Return value

An nsIDOMStorageItem object describing the data corresponding to the specified key, or null if no data exists for the given key.

key()

Returns the key for the item stored at the specified index in the data store.

DOMString key(
  in unsigned long index
);
Parameters
index
The index for which the corresponding key should be returned.
Return value

A string containing the requested key.

Exceptions thrown
INDEX_SIZE_ERR
There is no key at the specified index.

removeItem()

Given a key, removes the corresponding entry from the session store.

void removeItem(
  in DOMString key
);
Parameters
key
The key for which data should be removed from storage.

setItem()

Sets the value corresponding to a given key. If the key does not already exist, a new key is added, associated with the specified value. If the key already exists, the existing value is replaced with the specified value.

void setItem(
  in DOMString key,
  in DOMString data
);
Parameters
key
The key for which data should be set.
data
The data to associate with the specified key.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:122 次

字数:5624

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文