angular-local-storage
angular-local-storage copied to clipboard
browserSupportsLocalStorage returns wrong value when DOM Storage is disabled under IE11
browserSupportsLocalStorage always returns true if local storage is not supported when it should return false.
if the var supported is false the function never tries to set an item and returns true as the default. What should happen is that the function should return the value of supported instead of the hard coded value of true.
var browserSupportsLocalStorage = (function () {
try {
var supported = (storageType in $window && $window[storageType] !== null);
// When Safari (OS X or iOS) is in private browsing mode, it appears as though localStorage
// is available, but trying to call .setItem throws an exception.
//
// "QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage
// that exceeded the quota."
var key = prefix + '__' + Math.round(Math.random() * 1e7);
if (supported) {
webStorage.setItem(key, '');
webStorage.removeItem(key);
}
return supported;
} catch (e) {
storageType = 'cookie';
$rootScope.$broadcast('LocalStorageModule.notification.error', e.message);
return false;
}
}());
I think it is related to this issue http://stackoverflow.com/questions/21155137/javascript-localstorage-object-broken-in-ie11-on-windows-7 A potential code fix is to default to cookie storage instead of local storage by detecting the browser as mentioned.