How to check if ios uses private browsing

One of my jquery plugins has problems, and the problem occurs when private browsing is enabled on ios.

Is there any way to check this?

+4
javascript jquery safari ios
Oct 10
source share
2 answers

In private mode, the user cannot use local storage, try the following:

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; } } 
+13
Oct 10
source share

I found Answear on GitHub and tested it: Working with 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'); 
0
Dec 04 '17 at 9:31 on
source share



All Articles