jQuery detecting cookies enabled

前端 未结 6 972
失恋的感觉
失恋的感觉 2020-12-03 07:10

I have a jQuery-based web app. My requirement is fairly simple: I want to use jQuery to find out if the user has enabled or disabled cookies in their web browser. I\'m aware

6条回答
  •  [愿得一人]
    2020-12-03 07:47

    Why are you testing with the property cookieEnabled? just try to create a cookie and check if it's done. And in case cookies work, delete the test created cookie.

     function are_cookies_enabled()
        {
                document.cookie="testcookie=valid";
                cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
    
                if(cookieEnabled){
                   document.cookie = "testcookie=; expires=Thu, 01 Jan 1970 00:00:00 UTC;"; 
                }
    
                return cookieEnabled;
        }
    

提交回复
热议问题