Reputation: 193
I would block my website if cookies are disabled using Javascript or JQuery. Haw can I do that?
I know that I can check if cookies are enabled or not using navigator.cookieEnabled
and I thought to do a script that use an alert()
to say to the user to enable the cookies in order to be able to use the website and if he click ok I can call recursively my function which check if cookies are enabled and run the alert if not. This is my idea, but I don't know how to write it because it's my first approach to javascript. Can someone give me an advice? It's my idea the best way to implement it?
Upvotes: 1
Views: 894
Reputation: 1583
If you want to know how to know the user clicked the "ok" button on the alert, you can try this: Checking OK button is clicked on alert box
If you want to know whether the cookies is enabled and good to use, you can set cookies and read it again. Refer to below link to see how to set, read and check cookies: https://www.w3schools.com/js/js_cookies.asp
Upvotes: 1