Skip to content

Instantly share code, notes, and snippets.

@keelii
Created September 12, 2012 10:11
Show Gist options
  • Save keelii/3705735 to your computer and use it in GitHub Desktop.
Save keelii/3705735 to your computer and use it in GitHub Desktop.
IE userData storage solution!
var store = function(days) {
if ( typeof localStorage == 'undefined' ) {
var obj = document.createElement('q'),
days = days || 365;
obj.style.display = 'none';
obj.addBehavior('#default#userData');
var exp = new Date();
exp.setDate(exp.getDate() + days)
obj.expires = exp.toUTCString();
document.body.appendChild(obj);
this.name = location.hostname;
this.obj = obj;
} else {
return
}
};
store.prototype = {
set: function(name, val) {
this.obj.load(this.name);
this.obj.setAttribute(name, val);
this.obj.save(this.name);
},
get: function(name) {
this.obj.load(this.name);
return this.obj.getAttribute(name);
},
del: function(name) {
this.obj.load(this.name);
this.obj.removeAttribute(name);
this.obj.save(this.name);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment