1
我試圖檢測用戶是否在私人瀏覽器中查看網站。我有下面的代碼/小提琴,適用於Chrome和Firefox,但不適用於Safari。任何人都可以看到Safari的問題是什麼?先謝謝你。檢測隱私瀏覽 - Safari問題
new Promise(resolve => {
let db,
on =() => alert('yes'),
off =() => alert('no'),
tryls =() => {
try {
localStorage.length ? off() : (localStorage.x = 1, localStorage.removeItem("x"), off())
} catch (e) {
on()
}
}
// Blink
window.webkitRequestFileSystem ?
webkitRequestFileSystem(window.TEMPORARY, 1, off, on)
// FF
: "MozAppearance" in document.documentElement.style ?
(db = indexedDB.open("test"), db.onerror = on, db.onsuccess = off)
// Safari
: /constructor/i.test(window.HTMLElement) ?
tryls()
// IE10+ & edge
: !window.indexedDB && (window.PointerEvent || window.MSPointerEvent) ?
on()
// Rest
: off()
}).then(enabled => {
document.body.innerHTML = enabled
})
https://jsfiddle.net/ndyL5mxf/
這在Safari 11.0中不起作用了 – lustoykov