JSFiddle - React, Tailwind, and code Playground
by Dug Sohn
JavaScript
var visited = 0;
function cookieTest() {
if (visited == 0) {
var exdate=new Date();
exdate.setHours(23);
exdate.setMinutes(59);
exdate.setSeconds(59);
document.cookie='visited=1; expires='+exdate+'; path=/';
alert('Cookie set!');
}
else {
alert("you've been here before!");
}
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) visited = ( c.substring(nameEQ.length,c.length));
}
return null;
}
readCookie('visited');
cookieTest();