Skip to content

Instantly share code, notes, and snippets.

@Loknar
Last active January 1, 2017 14:20
Show Gist options
  • Save Loknar/99ac908f5999e51e6fe7b357d5ea3326 to your computer and use it in GitHub Desktop.
Save Loknar/99ac908f5999e51e6fe7b357d5ea3326 to your computer and use it in GitHub Desktop.
var localStorageWorks = function(debug) {
// simple test function to see if window.localStorage works
try {
window.localStorage.setItem("Test", "localStorageWorks");
if (window.localStorage.getItem("Test") !== "localStorageWorks") {
throw new Error("localStorage seems to be broken");
}
if (debug) {
console.log("localStorageWorks: returned positive")
}
return true;
}
catch (err) {
if (debug) {
console.warn("localStorageWorks: returned negative")
console.warn(err)
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment