Created
March 3, 2011 17:26
-
-
Save heapwolf/853134 to your computer and use it in GitHub Desktop.
A simplified way to store script state across browser refreshes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function() { | |
return window.sesh = { | |
init: function() { | |
var self = this; | |
window.addEventListener('unload', function() { | |
self.serialize(); | |
}, false); | |
self.parse(); | |
}, | |
data: {}, | |
serialize: function() { | |
var data = JSON.stringify(this.data); | |
if(data.length < 2000) { | |
window.name = data; | |
} | |
else { | |
throw new Error('The value may be too large to store depending on which browsers you plan on targeting.') | |
} | |
}, | |
parse: function() { | |
try { | |
this.data = JSON.parse(window.name); | |
} | |
catch(ex) {} | |
} | |
}; | |
})().init(); |
yeah i couldn't find a good lightweight implementation of this, everything was either really antiquated or ivory tower. this is a nice little extensible structure.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
niiice