如何识别以私有模式打开的Safari 11浏览器?

时间:2018-12-18 05:59:22

标签: javascript ios typescript browser safari

我的要求是,如果以私密方式打开野生动物园,我想在我的网站上显示一条消息。我尝试了本地存储检查,但所有这些在Safari 11中都无法使用。

上面的代码段不起作用。

,还尝试了:https://github.com/Maykonn/js-detect-incognito-private-browsing-paywall

   if (typeof localStorage === 'object') {
      try {
          localStorage.setItem('localStorage', 1);
          localStorage.removeItem('localStorage');
      } catch (e) {
          Storage.prototype._setItem = Storage.prototype.setItem;
          Storage.prototype.setItem = function() {};
          alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.');
      }
   }

这两个代码均不适用于Safari 11,但适用于chrome,FF和edge

0 个答案:

没有答案