admin管理员组文章数量:1296291
My jquerymobile App requires the use of localStorage and sessionstorage e.t.c, I've been giving a prompt to users without cookie support and telling them to enable cookies, but if a user has private browsing enable, this create cookie test I'm doing doesn't work and they just get a still erroneous screen, does anyone know how I could test if the user has private browsing enabled?
Thanks
My jquerymobile App requires the use of localStorage and sessionstorage e.t.c, I've been giving a prompt to users without cookie support and telling them to enable cookies, but if a user has private browsing enable, this create cookie test I'm doing doesn't work and they just get a still erroneous screen, does anyone know how I could test if the user has private browsing enabled?
Thanks
Share Improve this question asked Mar 11, 2012 at 21:34 williamsandonzwilliamsandonz 16.5k23 gold badges106 silver badges189 bronze badges 4- if i try create a localstorage entry when user is in this mode, the app bugs, even when in try catch – williamsandonz Commented Mar 11, 2012 at 23:00
- What is the specific error it throws? – levi Commented Mar 11, 2012 at 23:37
- its not throwing an error, it just fails silently! – williamsandonz Commented Mar 11, 2012 at 23:43
- oh wait got it, QUOTA_EXCEEDED_ERR:DOM Exception 22: An attempt was made to add something to storage – williamsandonz Commented Mar 11, 2012 at 23:58
1 Answer
Reset to default 9I don't have an Iphone to test this on, but in the desktop Safari browser (in private mode) running the below function does catch the error and handles it as expected.
function storageEnabled() {
try {
localStorage.setItem("__test", "data");
} catch (e) {
if (/QUOTA_?EXCEEDED/i.test(e.name)) {
return false;
}
}
return true;
}
if (!storageEnabled()) alert('localStorage not enabled');
Jsfiddle: http://jsfiddle/B9eZ5/
本文标签: javascriptHow to detect users on an iPhone with quotPrivate Browsingquot enabledStack Overflow
版权声明:本文标题:javascript - How to detect users on an iPhone with "Private Browsing" enabled? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741621006a2388809.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论