adding a test to verify the localStorage is supported fixing a bug on private browsing on safari
adding a test to verify the localStorage is supported fixing a bug on private browsing on safari

--- a/js/local_score_manager.js
+++ b/js/local_score_manager.js
@@ -18,9 +18,21 @@
   }
 };
 
+function isLocalStorageNameSupported() 
+{
+  var testKey = 'test', storage = window.localStorage;
+  try {
+    storage.setItem(testKey, '1');
+    storage.removeItem(testKey);
+    return true;
+  } 
+  catch (error) {
+    return false;
+  }
+}
+
 function LocalScoreManager() {
-  var localSupported = !!window.localStorage;
-
+  var localSupported = isLocalStorageNameSupported();
   this.key     = "bestScore";
   this.storage = localSupported ? window.localStorage : window.fakeStorage;
 }

comments