您好,欢迎来到码863代码分享网! 请[登录] / [注册]

js浏览器本地存储store.js

编辑

据浏览器自动选择使用 localStorage、globalStorage 或者 userData实现本地存储


项目地址:https://github.com/marcuswestin/store.js

store.js 是一个兼容所有浏览器的 LocalStorage 包装器,不需要借助 Cookie 或者 Flash。store.js 即可实现本地存储功能
store.js - 轻松实现本地存储(LocalStorage)
store.js 是一个兼容所有浏览器的 LocalStorage 包装器,不需要借助 Cookie 或者 Flash。store.js 会根据浏览器自动选择使用 localStorage、globalStorage 或者 userData 来实现本地存储功能。
store.js 提供非常简洁的 API 来实现跨浏览器的本地存储功能:

Tested in iOS 4+
Tested in Firefox 3.5
Tested in Firefox 3.6
Tested in Firefox 4.0+
Support dropped for Firefox < 3.5 (see notes below)
Tested in Chrome 5
Tested in Chrome 6
Tested in Chrome 7
Tested in Chrome 8
Tested in Chrome 10
Tested in Chrome 11+
Tested in Safari 4
Tested in Safari 5
Tested in IE6
Tested in IE7
Tested in IE8
Tested in IE9
Tested in IE10
Tested in Opera 10
Tested in Opera 11
Tested in Opera 12


Unsupported browsers   老版本不支持,ie7带特殊meta
    Firefox 1.0: no means (beside cookies and flash)
    Safari 2: no means (beside cookies and flash)
    Safari 3: no synchronous api (has asynch sqlite api, but store.js is synch)
    Opera 9: don't know if there is synchronous api for storing data locally
    Firefox 1.5: don't know if there is synchronous api for storing data locally
    Microsoft IIS & IE7: With meta tag & "charset=iso-8859-1", things stop working. See issue #47.

Storage limits
    IE6 & IE7: 1MB total, but 128kb per "path" or "document" (see http://msdn.microsoft.com/en-us/library/ms531424(v=vs.85).aspx)
    See http://dev-test.nemikor.com/web-storage/support-test/ for a list of limits per browser
    
    
例子
    
// Store 'marcus' at 'username'
store.set('username', 'marcus')

// Get 'username'
store.get('username')

// Remove 'username'
store.remove('username')

// Clear all keys
store.clear()

// Store an object literal - store.js uses JSON.stringify under the hood
store.set('user', { name: 'marcus', likes: 'javascript' })

// Get the stored object - store.js uses JSON.parse under the hood
var user = store.get('user')
alert(user.name + ' likes ' + user.likes)

// Get all stored values
store.getAll().user.name == 'marcus'

// Loop over all stored values
store.forEach(function(key, val) {
    console.log(key, '==', val)
})

CopyRight 2002~2023 精通2100网 联系邮箱:qqtxt@163.com
版权所有:精通2100网 湘ICP备2023018646号-1
MYSQl共执行 3 个查询,用时 0.15399384498596 秒,PHP脚本用时 0.156263 秒,占用内存 0.508 MB,Gzip 已启用