Merge pull request #2840 from ruslauz/fix/local-storage-spec-link
Fixes localStorage spec link
This commit is contained in:
commit
00bfa6da85
1 changed files with 3 additions and 3 deletions
|
@ -64,6 +64,7 @@ delete localStorage.test;
|
||||||
That's allowed for historical reasons, and mostly works, but generally not recommended, because:
|
That's allowed for historical reasons, and mostly works, but generally not recommended, because:
|
||||||
|
|
||||||
1. If the key is user-generated, it can be anything, like `length` or `toString`, or another built-in method of `localStorage`. In that case `getItem/setItem` work fine, while object-like access fails:
|
1. If the key is user-generated, it can be anything, like `length` or `toString`, or another built-in method of `localStorage`. In that case `getItem/setItem` work fine, while object-like access fails:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
let key = 'length';
|
let key = 'length';
|
||||||
localStorage[key] = 5; // Error, can't assign length
|
localStorage[key] = 5; // Error, can't assign length
|
||||||
|
@ -119,7 +120,6 @@ for(let key of keys) {
|
||||||
|
|
||||||
The latter works, because `Object.keys` only returns the keys that belong to the object, ignoring the prototype.
|
The latter works, because `Object.keys` only returns the keys that belong to the object, ignoring the prototype.
|
||||||
|
|
||||||
|
|
||||||
## Strings only
|
## Strings only
|
||||||
|
|
||||||
Please note that both key and value must be strings.
|
Please note that both key and value must be strings.
|
||||||
|
@ -148,7 +148,6 @@ Also it is possible to stringify the whole storage object, e.g. for debugging pu
|
||||||
alert( JSON.stringify(localStorage, null, 2) );
|
alert( JSON.stringify(localStorage, null, 2) );
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## sessionStorage
|
## sessionStorage
|
||||||
|
|
||||||
The `sessionStorage` object is used much less often than `localStorage`.
|
The `sessionStorage` object is used much less often than `localStorage`.
|
||||||
|
@ -180,7 +179,7 @@ That's exactly because `sessionStorage` is bound not only to the origin, but als
|
||||||
|
|
||||||
## Storage event
|
## Storage event
|
||||||
|
|
||||||
When the data gets updated in `localStorage` or `sessionStorage`, [storage](https://www.w3.org/TR/webstorage/#the-storage-event) event triggers, with properties:
|
When the data gets updated in `localStorage` or `sessionStorage`, [storage](https://html.spec.whatwg.org/multipage/webstorage.html#the-storageevent-interface) event triggers, with properties:
|
||||||
|
|
||||||
- `key` – the key that was changed (`null` if `.clear()` is called).
|
- `key` – the key that was changed (`null` if `.clear()` is called).
|
||||||
- `oldValue` – the old value (`null` if the key is newly added).
|
- `oldValue` – the old value (`null` if the key is newly added).
|
||||||
|
@ -221,6 +220,7 @@ Modern browsers also support [Broadcast channel API](mdn:/api/Broadcast_Channel_
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
Web storage objects `localStorage` and `sessionStorage` allow to store key/value in the browser.
|
Web storage objects `localStorage` and `sessionStorage` allow to store key/value in the browser.
|
||||||
|
|
||||||
- Both `key` and `value` must be strings.
|
- Both `key` and `value` must be strings.
|
||||||
- The limit is 5mb+, depends on the browser.
|
- The limit is 5mb+, depends on the browser.
|
||||||
- They do not expire.
|
- They do not expire.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue