Skip to content

Instantly share code, notes, and snippets.

@olivertappin
Created October 13, 2020 15:55
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 olivertappin/260e3c2be30549a27d2ac93a19393968 to your computer and use it in GitHub Desktop.
Save olivertappin/260e3c2be30549a27d2ac93a19393968 to your computer and use it in GitHub Desktop.
Detect whether cookies are enabled in the browser
function cookiesEnabled() {
if (navigator.cookieEnabled) {
return true;
}
document.cookie = 'cookietest=1';
let enabled = document.cookie.indexOf("cookietest=") !== -1;
document.cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
return enabled;
}
if (cookiesEnabled()) {
// Yay, cookies are enabled!
} else {
// Oh no, we can't use cookies!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment