Pop up help

I want to do something so that if you accept the 'Accept Cookies' button, then the popup won't show up again if you refresh the page. But if you reject it, then it will keep appearing. I think I have to use local storage for that. How can I do so? https://codepen.io/saad-shehzad-the-bashful/pen/YPzyLmJ
12 Replies
b1mind
b1mind2mo ago
Use a cookie? 🍪
Jochem
Jochem2mo ago
(I know b1's is a half-joke answer, but "reject cookies" means "reject tracking cookies". I'm 99% sure you're still allowed to use some functional cookies, as long as they can't be (and aren't) used to track the individual on your site or across sites. You can totally have a show_cookie_popup cookie set to 0) in fact, I'm pretty sure that if you have zero tracking cookies on the site, but only have functional ones (which has a set definition in the GDPR), you don't even have to show the popup. but IANAL
vince
vince2mo ago
You can also use local storage right? To store preferences of ui state
Jochem
Jochem2mo ago
I think "cookies" is a non-technical term when used in context of the GDPR. Pretty sure you can't just shift your tracking stuff to LocalStorage just cause it's not technically a cookie so yeah, you can totally use local storage too
Jochem
Jochem2mo ago
MDN Web Docs
Window: localStorage property - Web APIs | MDN
The localStorage read-only property of the window interface allows you to access a Storage object for the Document's origin; the stored data is saved across browser sessions.
vince
vince2mo ago
Ye just meant if you reject cookies you hide that preference in the local storage, else enable cookies actually sets the cookies But maybe it's better to just keep the preference as a cookie like you were suggesting since it's probably more semantic (and how most cookie consent pop-ups work anyway iirc, just wanted to propose an alternative)
Code-S ♛
Code-S ♛OP2mo ago
I can't seem to understand documentation. It's really hard, and there are so many concepts that haven't been clarified previously. Anyway, I was saying that I want the popup to not appear when you refresh the page if the user accepts it. If the user rejects it, then the popup should keep appearing when the user refreshes the page. This is what I want to achieve. Is local storage the easiest option? Is there any other way to do this? Is this exercise too advanced for me?
Jochem
Jochem2mo ago
both localstorage and cookies are easy and acceptable ways to accomplish this
clevermissfox
clevermissfox2mo ago
Is this the right documentation for the type of cookie you’re referring to? are these functional cookies?
MDN Web Docs
Using HTTP cookies - HTTP | MDN
A cookie (also known as a web cookie or browser cookie) is a small piece of data a server sends to a user's web browser. The browser may store cookies, create new cookies, modify existing ones, and send them back to the same server with later requests. Cookies enable web applications to store limited amounts of data and remember state informatio...
ἔρως
ἔρως2mo ago
i would use a cookie only because local storage may not be cleared when the user clears the browser information and when someone clears the cookies, that someone expects those annoying popups to be back
Jochem
Jochem2mo ago
I think "cookies" for the GDPR means "stored website data on the user's computer". Cookies like the link you sent used to be (in the dark old days) the only way you could store data. Whether they're functional or any of the other classes has nothing to do with the technical mechanism used to store them, but everything with their intended use if I store a cookie that stores whether the user is using dark mode or light mode, and I don't do anything with it other than set dark or light mode, that's a functional cookie if I store some data in LocalStorage and then use that to track my user's actions on my own site, that's analytical and needs permission afaik, as long as you only use functional cookies, you don't have to ask permission at all
ἔρως
ἔρως2mo ago
that is true, but when the user clears the browser data, the user (smart as an user can be) may or may not have the right option set to also clear localstorage as a means to cya, cookies work better

Did you find this page helpful?