Skip to content

Instantly share code, notes, and snippets.

@Victa
Created April 17, 2012 16:33
Show Gist options
  • Save Victa/2407337 to your computer and use it in GitHub Desktop.
Save Victa/2407337 to your computer and use it in GitHub Desktop.
Detect private browsing mode in mobile Safari on iOS5
var testKey = 'qeTest', storage = window.sessionStorage;
try {
// Try and catch quota exceeded errors
storage.setItem(testKey, '1');
storage.removeItem(testKey);
} catch (error) {
if (error.code === DOMException.QUOTA_EXCEEDED_ERR && storage.length === 0)
alert('Hello, private browser.');
else throw error;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment