Created
September 12, 2012 10:11
-
-
Save keelii/3705735 to your computer and use it in GitHub Desktop.
IE userData storage solution!
This file contains 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
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