Skip to content

Instantly share code, notes, and snippets.

@antoine-pous
Last active November 11, 2023 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoine-pous/d0a597ca756b5411ebd2 to your computer and use it in GitHub Desktop.
Save antoine-pous/d0a597ca756b5411ebd2 to your computer and use it in GitHub Desktop.
Check if cookies are available on the browser
/**
* "THE BEER-WARE LICENSE" (Revision 42):
* <gecko@dvp.io> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Antoine "Gecko" Pous
*/
cookieChecker = function() {
if (typeof navigator.cookieEnabled !== "undefined" ) {
document.cookie = "ac=test";
e = document.cookie.indexOf("ac") != -1 ? true : false;
document.cookie = "ac=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
return e;
}
return navigator.cookieEnabled;
}
// Usage :
if(cookieChecker()) {
//... do the stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment