【问题标题】:See if cookies are enabled at IE11 with high privacy settings查看是否在具有高隐私设置的 IE11 上启用了 cookie
【发布时间】:2016-10-17 13:53:19
【问题描述】:

我需要检查我的网站上是否启用了 cookie,当隐私设置设置为高或阻止所有 cookie 时,我遇到了 IE11 问题。我一直在使用 Javascript 并遵循这个question的答案@

代码如下:

    function checkCookie() {
        var cookieEnabled = (navigator.cookieEnabled) ? true : false;
        if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
            document.cookie = "testcookie";
            cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
        }
        return (cookieEnabled) ? true : showCookieFail();
    }

当设置设置为高或阻止所有 cookie 时,我还尝试了没有 cmets 中建议的第一行,因为 navigator.cookieEnabled = true

    function checkCookie2() {
        document.cookie = "testcookie";
        var cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
        return (cookieEnabled) ? true : showCookieFail();
    }

这两个选项都返回true,因此永远不会执行showCookieFail()。是我在代码中遗漏了什么,还是需要为 IE 制定其他解决方法?

【问题讨论】:

    标签: javascript cookies internet-explorer-11


    【解决方案1】:

    您确定在浏览器中禁用了 cookie 吗?当我将 cookie 设置设置为全部阻止时,您在上面粘贴的第一段代码似乎在 IE 11 上对我有用。它调用了 showCookieFail() 函数。

    【讨论】:

    • 经过更仔细的调查后,我确实看到创建了 cookie,尽管我确实尝试了所有不同类型的 cookie 设置来尝试在 IE 中阻止它们。因此,即使我设置了“阻止所有 cookie”设置,它们仍在创建中
    • 这确实是问题所在,由于某种原因,当我使用 VS 并测试我无法解释的 IE 时,IE 将 cookie 保留为会话 cookie。但我尝试将更改推送到现场设置,它在那里完美运行
    • 完美,很高兴你想通了!
    猜你喜欢
    • 2012-03-10
    • 2011-10-03
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 2021-05-21
    • 1970-01-01
    相关资源
    最近更新 更多