Browse Source

fixed storage when cookies disabled : return null if getItem exception

Nicolas Cannasse 14 years ago
parent
commit
d119c7eb55
1 changed files with 16 additions and 2 deletions
  1. 16 2
      std/js/Storage.hx

+ 16 - 2
std/js/Storage.hx

@@ -35,11 +35,25 @@ extern class Storage {
 	public function key( index : Int ) : String;
 
 	public static inline function getLocal() : Storage {
-		return untyped try window['localStorage'] catch( e : Dynamic ) null;
+		var s : Storage;
+		try {
+			s = untyped window['localStorage'];
+			s.getItem('');
+		} catch( e : Dynamic ) {
+			s = null;
+		}
+		return s;
 	}
 
 	public static inline function getSession() : Storage {
-		return untyped try window['sessionStorage'] catch( e : Dynamic ) null;
+		var s : Storage;
+		try {
+			s = untyped window['sessionStorage'];
+			s.getItem('');
+		} catch( e : Dynamic ) {
+			s = null;
+		}
+		return s;
 	}
 
 }