[BUGFIX] Check if client supports localStorage 42/56742/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 19 Apr 2018 17:15:13 +0000 (19:15 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Thu, 19 Apr 2018 18:34:51 +0000 (20:34 +0200)
Resolves: #84788
Releases: master, 8.7
Change-Id: If7a1c3e1b04c4de391d0bdb943d989971def6e8a
Reviewed-on: https://review.typo3.org/56742
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/backend/Resources/Public/JavaScript/Storage.js

index 5bbc58a..3408172 100644 (file)
@@ -56,12 +56,19 @@ define(['jquery'], function($) {
   };
 
   /**
+   * @returns {boolean}
+   */
+  Storage.Client.isCapable = function() {
+    return localStorage !== null;
+  };
+
+  /**
    * Simple localStorage wrapper, to get value from localStorage
    * @param {String} key
    * @return {String}
    */
   Storage.Client.get = function(key) {
-    return localStorage.getItem('t3-' + key);
+    return Storage.Client.isCapable() ? localStorage.getItem('t3-' + key) : null;
   };
 
   /**
@@ -70,7 +77,9 @@ define(['jquery'], function($) {
    * @param {String} value
    */
   Storage.Client.set = function(key, value) {
-    localStorage.setItem('t3-' + key, value);
+    if (Storage.Client.isCapable()) {
+      localStorage.setItem('t3-' + key, value);
+    }
   };
 
   /**
@@ -78,14 +87,18 @@ define(['jquery'], function($) {
    * @param {String} key
    */
   Storage.Client.unset = function(key) {
-    localStorage.removeItem('t3-' + key);
+    if (Storage.Client.isCapable()) {
+      localStorage.removeItem('t3-' + key);
+    }
   };
 
   /**
    * Simple localStorage wrapper, to clear localStorage
    */
   Storage.Client.clear = function() {
-    localStorage.clear();
+    if (Storage.Client.isCapable()) {
+      localStorage.clear();
+    }
   };
 
   /**
@@ -95,8 +108,12 @@ define(['jquery'], function($) {
    * @returns {Boolean}
    */
   Storage.Client.isset = function(key) {
-    var value = this.get(key);
-    return (typeof value !== 'undefined' && value !== null);
+    if (Storage.Client.isCapable()) {
+      var value = this.get(key);
+      return (typeof value !== 'undefined' && value !== null);
+    }
+
+    return false;
   };
 
   /**