aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/storageevent/index.html
blob: eceb17bb94d915f00ef13cbfaf7682029ed606d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
title: StorageEvent
slug: Web/API/StorageEvent
tags:
  - 本地存储
translation_of: Web/API/StorageEvent
---
<p>{{APIRef("Web Storage API")}}</p>

<p>当前页面使用的storage被其他页面修改时会触发StorageEvent事件. </p>

<p>[译者:事件在同一个域下的不同页面之间触发,即在A页面注册了storge的监听处理,只有在跟A同域名下的B页面操作storage对象,A页面才会被触发storage事件] </p>

<p>{{InheritanceDiagram}}</p>

<div class="note">
<p><strong>Note:</strong> 尽管这个事件已经早在 {{ Gecko("2.0") }}时就已存在,但是并不符合规范. 老的事件模型直到 {{ interface("nsIDOMStorageEventObsolete") }} 确定才被表现出来.</p>
</div>

<h2 id="方法描述">方法描述</h2>

<pre><code>void initStorageEvent(
  in DOMString typeArg,
  in boolean canBubbleArg,
  in boolean cancelableArg,
  in DOMString keyArg,
  in DOMString oldValueArg,
  in DOMString newValueArg,
  in DOMString urlArg,
  in nsIDOMStorage storageAreaArg
);</code>
</pre>

<h2 id="Method_overview" name="Method_overview">属性</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <td class="header">属性名</td>
   <td class="header">类型</td>
   <td class="header">描述</td>
  </tr>
  <tr>
   <td><code>key</code></td>
   <td><code><a href="/en/DOMString" title="en/DOMString">DOMString</a></code></td>
   <td>该属性代表被修改的键值。当被<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">clear()</span></font>方法清除之后该属性值为<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">null</span></font><strong>(只读)</strong></td>
  </tr>
  <tr>
   <td><code>newValue</code></td>
   <td><code><a href="/en/DOMString" title="en/DOMString">DOMString</a></code></td>
   <td>该属性代表修改后的新值。当被<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">clear()</span></font>方法清理后或者该键值对被移除,<code>newValue</code> 的值为 <code>null</code><strong>(只读)</strong></td>
  </tr>
  <tr>
   <td><code>oldValue</code></td>
   <td><code><a href="/en/DOMString" title="en/DOMString">DOMString</a></code></td>
   <td>该属性代表修改前的原值。在设置新键值对时由于没有原始值,该属性值为 <code>null</code><strong>(只读)</strong></td>
  </tr>
  <tr>
   <td><code>storageArea</code></td>
   <td><code>{{ Interface("nsIDOMStorage") }}</code></td>
   <td>被操作的storage对象。<strong>(只读)</strong></td>
  </tr>
  <tr>
   <td><code>url</code></td>
   <td><code><a href="/en/DOMString" title="en/DOMString">DOMString</a></code></td>
   <td>
    <p><font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">key</span></font> 发生改变的对象所在文档的URL地址。<strong>(只读)</strong></p>
   </td>
  </tr>
 </tbody>
</table>

<h2 id="Methods" name="Methods">方法</h2>

<h3 id="initStorageEvent()" name="initStorageEvent()">initStorageEvent()</h3>

<p>类似DOM中的初始化事件,即初始化新创建的Storage对象的属性。</p>

<pre class="eval" dir="rtl">void initStorageEvent(
  in DOMString typeArg,
  in boolean canBubbleArg,
  in boolean cancelableArg,
  in DOMString keyArg,
  in DOMString oldValueArg,
  in DOMString newValueArg,
  in DOMString urlArg,
  in nsIDOMStorage storageAreaArg
);</pre>

<dl>
 <dt>参数:</dt>
 <dt><code>typeArg</code></dt>
 <dd>事件名</dd>
 <dt><code>canBubbleArg</code></dt>
 <dd>布尔值,代表是否可以通过dom冒泡</dd>
 <dt><code>cancelableArg</code></dt>
 <dd>布尔值,代表是否可以注销事件</dd>
 <dt><code>keyArg</code></dt>
 <dd>事件结果时被改变的值对应的属性名称</dd>
 <dt><code>oldValueArg</code></dt>
 <dd>旧值</dd>
 <dt><code>newValueArg</code></dt>
 <dd>新值</dd>
 <dt><code>urlArg</code></dt>
 <dd>事件初始化时页面的url</dd>
 <dt><code>storageAreaArg</code></dt>
 <dd> 发生在哪个storage对象上</dd>
</dl>

<h2 id="See_also" name="See_also">参阅</h2>

<ul>
 <li> <a class="external" href="http://dev.w3.org/html5/webstorage/#the-storage-event" title="http://dev.w3.org/html5/webstorage/#the-storage-event">Specification</a></li>
</ul>