Skip to content

Instantly share code, notes, and snippets.

@aliirz
Created November 4, 2013 12:54
Show Gist options
  • Save aliirz/7302031 to your computer and use it in GitHub Desktop.
Save aliirz/7302031 to your computer and use it in GitHub Desktop.
Using Local storage or jquery cookie
tab.Storage = _.extend({
setItem: function (itemID, value) {
if('localStorage' in window && window['localStorage'] !== null){
localStorage.setItem(itemID, value);
}else{
$.cookie(itemID, value, { path: '/' });
}
},
getItem: function (itemID) {
if('localStorage' in window && window['localStorage'] !== null){
return localStorage.getItem(itemID);
}else{
return $.cookie(itemID);
}
},
clear: function (){
if('localStorage' in window && window['localStorage'] !== null){
localStorage.clear();
}else{
$.clearCookies();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment