Search code examples
javascriptjqueryiossafari

How to check if ios is using private browsing


One of my jquery plugins is having issues, and the issue occurs when private browsing is turned on in ios.

Is there a way to check this?


Solution

  • In private mode user can't use local storage try this:

    var storageTestKey = 'sTest',
        storage = window.sessionStorage;
    
    try {
      storage.setItem(storageTestKey, 'test');
      storage.removeItem(storageTestKey);
    } catch (e) {
      if (e.code === DOMException.QUOTA_EXCEEDED_ERR && storage.length === 0) {
        // private mode
      } else {
        throw e;
      }
    }