I have created a content locker(click link to open content) but now I am stuck on the cookie part. Once you've clicked the particular link the content locker must not appear again for 30 days. I have created the onclick cookie and it works, but I can't seem to be able to set the number of days the cookie must remain(whatever I do its set as a session cookie) and I also don't know how to read the cookie on pageload so that it doesn't show the content locker again. I am not a javascript expert at all, everything i've managed so far is from googling. Here's my code
myDate = new Date('31/12/2020 12:00 UTC');
document.cookie = 'clicklink=yes; expires=' + myDate.toString + ';';
onclick="alert(document.cookie);">
Please help
To set a cookie:
To get a cookie:
Check if cookie exists on page load
HTML
Go through this link for more details
And I would suggest you to read about HTML5 storage APIs. It is similar to cookie but more efficient and simple
as Chris stated:
You can read more about cookies here.
To set the cookie:
To show the cookie:
Of course this should be done with an eventListener, so it is not that easily tampered.
A function to get the cookie:
To check if your cookie is set: