4

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?

1
  • BTW: My opinion is a web app shouldn't be able to tell a difference, and it's a browser bug if it can. (This obviously doesn't solve your problem though; I wonder what's the reason.)
    – Kos
    Commented Oct 10, 2012 at 14:58

2 Answers 2

12

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;
  }
}
3
  • Can't tell on iOS, but doesn't work in Chrome. Here's a fiddle: jsfiddle.net/n49yQ
    – Kos
    Commented Oct 10, 2012 at 14:56
  • 2
    That's because Safari and Chrome handle the idea of storage during a private session differently. Chrome will still allow temporary session storage when in 'incognito' mode, whereas Safari disable access completely. I prefer Chrome's implementation because HTML5 apps will still be able to cache their files/images.
    – stevokk
    Commented Jan 21, 2013 at 14:59
  • 1
    @Kos Your jsfiddle does not work anymore. Here is a working fiddle: jsfiddle.net/harianus/aueb9u74 It alerts when Safari Prived mode is detected.
    – adriaan
    Commented Jul 22, 2015 at 8:37
5

I've found an Answear at GitHub and tested it: Working on IOS 11!

var isPrivate = false;
try {
  window.openDatabase(null, null, null, null);
} catch (_) {
  isPrivate = true;
}
alert((isPrivate ? 'You\'re' : 'You aren\'t')  + ' in private browsing mode');
1
  • Does not appear to work anymore in IOS 13.0, but oddly enough, in IOS 13.0.1 it's fine again.
    – Eon
    Commented Oct 10, 2019 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.