Last active
August 29, 2015 14:06
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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