Simplest way to check if cookies are enabled or disabled - JavaScript

How can I make a simple check if cookies are enabled or disabled, using JavaScript ?
0
give a positive ratinggive a negative rating
03 Nov 2023 at 12:17 PM
Hi,

To make a simple check if cookies are enabled or disabled in visitor's web browser, you can use the following solution:

function checkCookies(){

document.cookie='c=1';
var v = document.cookie.indexOf("c=")!=-1;
document.cookie = 'c=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
if(v===true){ alert('Cookies are enabled'); }
else{ alert('Cookies are disabled'); }
}

1
give a positive ratinggive a negative rating
06 Nov 2023 at 11:42 AM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us