/ Published in: JavaScript
Provides getter/setter functionality for objects in local storage. Utilizes JSON.stringify and JSON.parse.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
if (window.Storage) { Storage.prototype.setObject = function(key, value) { this.setItem(key, JSON.stringify(value)); } Storage.prototype.getObject = function(key) { try { return JSON.parse(this.getItem(key)); } catch(e) { return null; } } }