如何使用“私人浏览”检测iPhone上的用户启用? [英] How to detect users on an iPhone with "Private Browsing" enabled?

查看:95
本文介绍了如何使用“私人浏览”检测iPhone上的用户启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jquerymobile应用程序需要使用localStorage和sessionstorage等,我一直向没有cookie支持的用户发出提示并告诉他们启用cookie,但是如果用户启用了私有浏览,那么创建cookie测试我就是做不起作用,他们只是得到一个仍然错误的屏幕,有人知道我如何测试用户是否启用了隐私浏览?

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?

谢谢

推荐答案

我没有Iphone来测试这个,但在桌面Safari浏览器(在私人模式下)运行以下功能确实赶上了错误并按预期处理。

I 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.net/B9eZ5/

Jsfiddle: http://jsfiddle.net/B9eZ5/

这篇关于如何使用“私人浏览”检测iPhone上的用户启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆