@@ -70,7 +70,7 @@ angularLocalStorage.provider('localStorageService', function() {
7070 var cookie = this . cookie ;
7171 var notify = this . notify ;
7272 var storageType = this . storageType ;
73- var webStorage = $window [ storageType ] ;
73+ var webStorage ;
7474
7575 // When Angular's $document is not available
7676 if ( ! $document ) {
@@ -96,6 +96,7 @@ angularLocalStorage.provider('localStorageService', function() {
9696 // that exceeded the quota."
9797 var key = deriveQualifiedKey ( '__' + Math . round ( Math . random ( ) * 1e7 ) ) ;
9898 if ( supported ) {
99+ webStorage = $window [ storageType ] ;
99100 webStorage . setItem ( key , '' ) ;
100101 webStorage . removeItem ( key ) ;
101102 }
@@ -107,6 +108,8 @@ angularLocalStorage.provider('localStorageService', function() {
107108 return false ;
108109 }
109110 } ( ) ) ;
111+
112+
110113
111114 // Directly adds a value to local storage
112115 // If local storage is not available in the browser use cookies
@@ -131,7 +134,7 @@ angularLocalStorage.provider('localStorageService', function() {
131134 if ( angular . isObject ( value ) || angular . isArray ( value ) ) {
132135 value = angular . toJson ( value ) ;
133136 }
134- webStorage . setItem ( deriveQualifiedKey ( key ) , value ) ;
137+ if ( webStorage ) { webStorage . setItem ( deriveQualifiedKey ( key ) , value ) } ;
135138 if ( notify . setItem ) {
136139 $rootScope . $broadcast ( 'LocalStorageModule.notification.setitem' , { key : key , newvalue : value , storageType : this . storageType } ) ;
137140 }
@@ -151,7 +154,7 @@ angularLocalStorage.provider('localStorageService', function() {
151154 return getFromCookies ( key ) ;
152155 }
153156
154- var item = webStorage . getItem ( deriveQualifiedKey ( key ) ) ;
157+ var item = webStorage ? webStorage . getItem ( deriveQualifiedKey ( key ) ) : null ;
155158 // angular.toJson will convert null to 'null', so a proper conversion is needed
156159 // FIXME not a perfect solution, since a valid 'null' string can't be stored
157160 if ( ! item || item === 'null' ) {
0 commit comments