Permalink
Browse files

Changing the way that the test for local storage availability is perf…

…ormed.
  • Loading branch information...
1 parent aff465f commit eecf6a6d93cafb3f427da2031ab87aadc78ab1f9 @brianantonelli brianantonelli committed Jul 16, 2012
Showing with 10 additions and 8 deletions.
  1. +10 −8 jquery.enhanced.cookie.js
View
@@ -1,4 +1,3 @@
-
/**
* jQuery Extended Cookie Plugin
*
@@ -14,14 +13,17 @@
jQuery.cookie = function (key, value, options) {
// Check if localStorage of HTML5 exists in this browser
- var isStorageAvailable;
- try {
- isStorageAvailable = window.localStorage;
- isStorageAvailable.setItem("isStorageAvailable", "true");
- if (isStorageAvailable.getItem("isStorageAvailable") != "true") {
- isStorageAvailable = false;
+ var isStorageAvailable = false;
+ if ("localStorage" in window)
+ {
+ try {
+ window.localStorage.setItem("isStorageAvailable", "true");
+ isStorageAvailable = true;
+ window.localStorage.removeItem("isStorageAvailable", "true");
+ } catch (PrivateBrowsingError) {
+ // iOS Private Browsing mode will throw a "QUOTA_EXCEEDED_ERRROR DOM Exception 22" error
}
- } catch(e) {}
+ }
// Check if the user wants to create or delete a cookie.
if (arguments.length > 1 && String(value) !== "[object Object]")

0 comments on commit eecf6a6

Please sign in to comment.