I need to check if cookies are enabled on my website and I'm running into problems with IE11 when the settings for privacy are set to high or to block all cookies. I've been using Javascript and followed the answer from this question
The code is as follows:
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();
}
I also tried without the first line as suggested in the comments since navigator.cookieEnabled = true
when the settings are set to high or to block all cookies
function checkCookie2() {
document.cookie = "testcookie";
var cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
return (cookieEnabled) ? true : showCookieFail();
}
Both these options return true
so showCookieFail()
is never executed. Is it something I'm missing in the code or is there some other workaround that needs to be made for IE?