window.localStorage

来源:互联网 发布:数据库被黑客删除 编辑:程序博客网 时间:2024/06/06 18:38

API

window.localStorage.getItem('key'): equal to window.localStorage['key']; return the value (String) stored before; return null if not existing.
window.localStorage.setItem('key', 'value'): store key/value to localStorage; Be aware that value must be String. If passing in an object, toString() method will be called and returned value (‘[object Object]’) will be stored. You should use JSON.stringify() transform the object to String for storage.
window.localStorage.removeItem('key'): remove the key/value stored earlier. It will do nothing if the key does not exist.

Browser compatibility

Feature Chrome Edge Internet Explorer Firefox Opera Safari localStorage 4 yes 8 3.5 10.50 4
原创粉丝点击