Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save marcustallberg/d3618974e01c012442e8 to your computer and use it in GitHub Desktop.

Select an option

Save marcustallberg/d3618974e01c012442e8 to your computer and use it in GitHub Desktop.
Workaround for iOS private browsing bug where localStorage is available but the storage quota is 0.
/*
Problem: http://stackoverflow.com/questions/14555347/html5-localstorage-error-with-safari-quota-exceeded-err-dom-exception-22-an
Solution: Workaround stores the same key/value pair with jquery.cookie and overrides the original get/set methods of localStorage.
Dependency: https://github.com/carhartl/jquery-cookie
*/
function hasTrueLocalStorage(){
try {
localStorage.setItem("foo", true);
localStorage.removeItem("foo");
return true;
}
catch(e) {
return false;
}
}
if(!hasTrueLocalStorage()){
Storage.prototype.setItem = function(key, value) {
$.cookie(key, value);
}
Storage.prototype.getItem = function(key) {
var itemVal = $.cookie(key);
return itemVal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment