Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dev0x10/cf86633733c1bbfc29247df327f79859 to your computer and use it in GitHub Desktop.

Select an option

Save dev0x10/cf86633733c1bbfc29247df327f79859 to your computer and use it in GitHub Desktop.

Revisions

  1. @philfreo philfreo revised this gist Nov 22, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions localstorage_safari_private_shim.js
    Original file line number Diff line number Diff line change
    @@ -8,5 +8,6 @@ if (typeof localStorage === 'object') {
    } catch (e) {
    Storage.prototype._setItem = Storage.prototype.setItem;
    Storage.prototype.setItem = function() {};
    alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.');
    }
    }
  2. @philfreo philfreo revised this gist Nov 22, 2014. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions localstorage_safari_private_shim.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    // Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
    // throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
    // to avoid the entire page breaking.
    if (typeof localStorage === 'object') {
    try {
    localStorage.setItem('localStorage', 1);
    localStorage.removeItem('localStorage');
    } catch (e) {
    Storage.prototype._setItem = Storage.prototype.setItem;
    Storage.prototype.setItem = function() {};
    }
    }
    // Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
    // throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
    // to avoid the entire page breaking, without having to do a check at each usage of Storage.
    if (typeof localStorage === 'object') {
    try {
    localStorage.setItem('localStorage', 1);
    localStorage.removeItem('localStorage');
    } catch (e) {
    Storage.prototype._setItem = Storage.prototype.setItem;
    Storage.prototype.setItem = function() {};
    }
    }
  3. @philfreo philfreo created this gist Nov 22, 2014.
    12 changes: 12 additions & 0 deletions localstorage_safari_private_shim.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    // Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
    // throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
    // to avoid the entire page breaking.
    if (typeof localStorage === 'object') {
    try {
    localStorage.setItem('localStorage', 1);
    localStorage.removeItem('localStorage');
    } catch (e) {
    Storage.prototype._setItem = Storage.prototype.setItem;
    Storage.prototype.setItem = function() {};
    }
    }