Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to check if cookies are enabled with modernizr?

I was researching about how to check if the cookies are enabled in a browser and i found a lot of answer, i even tested a few ones, but after that a friend of mine suggest me to use Modernizr for that.
I started to search about that and i found a lot of stuff related with CSS3 and HTML5, but i don't want that, i just wanna know if is it possible to check that cookies are enabled or not with Modernizr?

like image 778
ddieppa Avatar asked Feb 03 '12 14:02

ddieppa


People also ask

How do you check if cookies are enabled PHP?

Check if Cookies are Enabledsetcookie("test_cookie", "test", time() + 3600, '/');


2 Answers

check this url, hope it's helpful :

https://github.com/Modernizr/Modernizr/commit/33f00fbbeb12e92bf24711ea386e722cce6f60cc

like image 102
mgraph Avatar answered Sep 21 '22 15:09

mgraph


Below code is copied from http://sveinbjorn.org/cookiecheck.

function are_cookies_enabled()
{
    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);
}
like image 22
oldmonk Avatar answered Sep 19 '22 15:09

oldmonk