@@ -42,9 +42,9 @@ localStorage.setItem('test', 1);
42
42
alert ( localStorage .getItem (' test' ) ); // 1
43
43
```
44
44
45
- We only have to be on the same domain/port/protocol, the url path can be different.
45
+ We only have to be on the same origin ( domain/port/protocol) , the url path can be different.
46
46
47
- The ` localStorage ` is shared, so if we set the data in one window, the change becomes visible in the other one.
47
+ The ` localStorage ` is shared between all windows with the same origin , so if we set the data in one window, the change becomes visible in another one.
48
48
49
49
## Object-like access
50
50
@@ -73,7 +73,7 @@ That's allowed for historical reasons, and mostly works, but generally not recom
73
73
74
74
## Looping over keys
75
75
76
- As we' ve seen, the methods provide get/set/remove functionality. But how to get all saved values or keys?
76
+ As we' ve seen, the methods provide " get/set/remove by key" functionality. But how to get all saved values or keys?
77
77
78
78
Unfortunately, storage objects are not iterable.
79
79
@@ -198,7 +198,7 @@ Imagine, you have two windows with the same site in each. So `localStorage` is s
198
198
You might want to open this page in two browser windows to test the code below.
199
199
` ` `
200
200
201
- Now if both windows are listening for ` window.onstorage` , then each one will react on updates that happened in the other one.
201
+ If both windows are listening for ` window.onstorage` , then each one will react on updates that happened in the other one.
202
202
203
203
` ` ` js run
204
204
// triggers on updates made to the same storage from other documents
@@ -229,18 +229,18 @@ Web storage objects `localStorage` and `sessionStorage` allow to store key/value
229
229
| ` localStorage` | ` sessionStorage` |
230
230
| ---------------- | ------------------ |
231
231
| Shared between all tabs and windows with the same origin | Visible within a browser tab, including iframes from the same origin |
232
- | Survives browser restart | Dies on tab close |
232
+ | Survives browser restart | Survives page refresh (but not tab close) |
233
233
234
234
API :
235
235
236
236
- ` setItem(key, value)` -- store key/ value pair.
237
237
- ` getItem(key)` -- get the value by key.
238
238
- ` removeItem(key)` -- remove the key with its value.
239
239
- ` clear()` -- delete everything.
240
- - ` key(index)` -- get the key on a given position .
240
+ - ` key(index)` -- get the key number ` index ` .
241
241
- ` length` -- the number of stored items.
242
242
- Use ` Object.keys` to get all keys.
243
- - Can use the keys as object properties, in that case ` storage` event isn' t triggered.
243
+ - We access keys as object properties, in that case ` storage` event isn' t triggered.
244
244
245
245
Storage event:
246
246
0 commit comments