<html>
<head>
<meta charset=utf-8 />
<title>isPrivateMode</title>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script>
</head>
<body>
<h4>Testing</h4>
<p>
<code>isPrivateMode(): Promise</code>
</p>
<hr />
<p>
An <code>alert()</code> will notify if you are browsing in private mode.
</p>
<hr />
<aside>
<code>Promise</code> object is polyfilled.
</aside>
</body>
</html>
aside {
font-style: italic;
}
function isPrivateMode() {
"use strict";
return new Promise(function (resolve) {
// is in private mode
var yes = function yes() {
return resolve(true);
};
// not in private mode
var not = function not() {
return resolve(false);
};
var testLocalStorage = function testLocalStorage() {
try {
if (localStorage.length) not();
else {
localStorage.x = 1;
localStorage.removeItem('x');
not();
}
} catch (e) {
// Safari only enables cookie in private mode
// if cookie is disabled, then all client side storage is disabled
// if all client side storage is disabled, then there is no point
// in using private mode
navigator.cookieEnabled ? yes() : not();
}
};
// Chrome & Opera
var fs = window.webkitRequestFileSystem || window.RequestFileSystem;
if (fs) {
return void fs(window.TEMPORARY, 100, not, yes);
}
// Firefox
if ('MozAppearance' in document.documentElement.style) {
if (indexedDB === null) return yes();
var db = indexedDB.open('test');
db.onerror = yes;
db.onsuccess = not;
return void 0;
}
// Safari
var isSafari = navigator.userAgent.match(/Version\/([0-9\._]+).*Safari/);
if (isSafari) {
var version = parseInt(isSafari[1], 10);
if (version < 11) return testLocalStorage();
try {
window.openDatabase(null, null, null, null);
return not();
} catch (_) {
return yes();
}
}
// IE10+ & Edge InPrivate
if (!window.indexedDB && (window.PointerEvent || window.MSPointerEvent)) {
return yes();
}
// default navigation mode
return not();
});
}
isPrivateMode().then(function (isPrivate) {
alert('Browsing in private mode? ' + isPrivate);
});
You can jump to the latest bin by adding /latest
to your URL
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + [ | Indents selected lines |
ctrl + ] | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Clone Bin |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |