跨浏览器的本地存储解决方案(localStorage)
判断浏览器内核:
Browser.Engine.gecko??? -> firefox内核
Browser.Engine.webkit?? -> chrome 内核
Browser.Engine.trident? -> IE 内核
基本上现在主流浏览器 都支持 localStorage!
?
因此,拟使用localStorage来作为前端存储主干方案!
ie6 ie7? 可以使用userdata! 话说现在还有人在用吗。。。
?
/** * 本地存储类 * -------------------- * USAGE * Storage.write("key", "value"); * Storage.read("key"); * -------------------- * @author: superho */(function() { var storage = new Class({ initialize: function(key){ this.key = key; }, write: function(value) {}, read: function() {}, dispose: function() {} });storage.implement({write: function(value) { localStorage.setItem(this.key, JSON.encode(value));}, read: function() {var item = localStorage.getItem(this.key); if (item) { return JSON.decode(item); }return null; }, dispose: function() { return localStorage.removeItem(this.key); } }); this.Storage = storage;})();$extend(Storage, { write: function(key, value) { new Storage(key).write(value); }, read: function(key) { return new Storage(key).read(); }, remove: function(key) { new Storage(key).dispose(); }});?
?
?
?