查看是否在具有高隐私设置的 IE11 上启用了 cookie

See if cookies are enabled at IE11 with high privacy settings

我需要检查我的网站是否启用了 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();
    }

我也尝试过不使用评论中建议的第一行,因为 navigator.cookieEnabled = true 当设置设置为高或阻止所有 cookie

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

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

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