Skip to content

Instantly share code, notes, and snippets.

@xergioalex
Created December 14, 2015 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xergioalex/974c2e286f4c3c26b8a6 to your computer and use it in GitHub Desktop.
Save xergioalex/974c2e286f4c3c26b8a6 to your computer and use it in GitHub Desktop.
Utils = {
// Detect if support local storage
supports_html5_storage: function () {
try {
localStorage.setItem('testKey', 'test');
localStorage.removeItem('testKey');
return true;
} catch (e) {
return false;
}
},
// Save data in browser
saveDataInBrowser: function (key, data) {
if (this.supports_html5_storage()) {
localStorage.setItem(key, data);
} else {
$.cookie(key, data, { path: '/' });
}
},
// Save data in browser
getDataFromBrowser: function (key) {
if (this.supports_html5_storage()) {
return localStorage.getItem(key);
} else {
return $.cookie('laboratoryBackup');
}
},
// Remove data in browser
removeDataInBrowser: function (key) {
if (this.supports_html5_storage()) {
localStorage.removeItem(key);
} else {
$.removeCookie('key', { path: '/' });
}
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment