Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery detecting cookies enabled

Tags:

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 that there's a plugin available which can be used to create/retrieve/delete/update a cookie. But, is there a way jQuery can detect the user agent's settings?

like image 273
user1044304 Avatar asked Nov 13 '11 15:11

user1044304


People also ask

How check cookie is set or not in jquery?

If this is the case, then you can actually check if a user has enabled cookies or not using the following straightforward jQuery snippet: $(document). ready(function() { var dt = new Date(); dt. setSeconds(dt.

How do you check if cookies are enabled JavaScript?

To check whether a setting a cookie is enabled in the browser, you can use the cookieEnabled property in the window. navigator global object in JavaScript. The property will return a Boolean true if cookie enabled and return false if not enabled.

How do I enable cookies in JavaScript?

At the top right corner, click Settings and more , then choose Settings. Select Cookies and site permissions. Click Manage and delete cookies and site data, then turn ON Allow sites to save and read cookie data (recommended). Select JavaScript under Site permissions, then turn ON Allowed (recommended).


1 Answers

You don't need jQuery for that, you can use vanilla Javascript:

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); } 

http://sveinbjorn.org/cookiecheck

like image 84
Sarfraz Avatar answered Sep 29 '22 19:09

Sarfraz