Skip to content

Instantly share code, notes, and snippets.

@danb-humaan
Last active March 21, 2016 08:48
Show Gist options
  • Save danb-humaan/4b43cdb5e7be1426edfd to your computer and use it in GitHub Desktop.
Save danb-humaan/4b43cdb5e7be1426edfd to your computer and use it in GitHub Desktop.
/**
* Determines whether the browser supports localStorage or not.
*
* This method is required due to iOS Safari in Private Browsing mode incorrectly says it supports localStorage, when it in fact does not.
*
* @kind function
* @function LocalStorage#supportsLocalStorage
*
* @returns {boolean} Returns true if setting and removing a localStorage item is successful, or false if it's not.
*/
supportsLocalStorage: function () {
try {
localStorage.setItem('_', '_');
localStorage.removeItem('_');
return true;
} catch (e) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment