首先看下兼容性
在看下存在的坑:
- Storing large amounts of data in Safari (on OSX & iOS) can result in freezing the browser
(存储大量的数据在 safari中,会导致浏览器崩溃的)
- IE10 in Windows 8 has an issue where localStorage can fail with the error message "SCRIPT5: Access is denied" if "integrity" settings are not set correctly. see details
(在win8 的IE10 中有一个问题: 如果设置不正确的话的话 localstorage会抛出一个异常错误:SCRIPT5: Access is denied)
- The "storage" event is completely wrong in IE: (IE里面的错误)
IE10 : The storage event is fired even on the originating document where it occurred. Causes problems with multiple windows websites, and huge problems with iframes.
(存储事件触发即使在原始文档发生。导致多个窗口网站问题,和巨大的iframes的问题)
IE11 : The storage event's oldValue and newValue are identical (newValue is supposed to contain the storage's updated value).
(存储事件的oldValue和newValue是相同的(newValue应该包含存储的更新值))
Partial workaround: regularly probe the storage's value and compare with the last known value on all pages where you want to listen to this event, and track the last submitted value to determine if the modification was triggered locally.
(部分处理:定期调查存储的值,与去年相比已知值在所有页面,你想听这个事件,并跟踪最后提交的值来确定是否在本地修改被触发。)
- Internet Explorer does not support storing most of the ASCII characters with codes under x20.
(Internet Explorer不支持存储ASCII字符与编码x20。)
- In IE attempting to access localStorage on HTML files served from the file system results in the localStorage object being undefined
(在IE中试图访问localStorage HTML文件从文件系统服务结果在localStorage对象被定义)
- In iOS 5 & 6 localStorage data is stored in a location that may occasionally be cleared out by the OS.
(在iOS 5 & 6 localStorage数据存储在一个位置,偶尔会被清除的操作系统。)
- In private browsing mode, Safari and iOS Safari up to including version 10.x as well as the Android browser (not include Chrome for Android) do not support setting sessionStorage or localStorage.
(在隐私浏览模式下,Safari和iOS Safari包括版本10。x以及Android浏览器(不包括铬为Android)不支持设置sessionStorage或localStorage。)
- IE 8 and 9 store data based only on hostname, ignoring the scheme (http vs https) and port number as required by the specification.
(IE 8和9只基于主机名存储数据,忽略了方案(http和https)和端口号的要求规范。)
- IE11 does not properly synchronize localStorage between different windows.
(IE11不正确同步localStorage不同窗口)