简体   繁体   English

如何在 ReactJS/HTML/CSS 网站中实现 cookie 同意并能够关闭 cookie?

[英]How to implement cookies consent in ReactJS/HTML/CSS website with ability to turn cookies off?

I am working on a website and we currently have a cookie banner which displays on launch and has a ok button.我在一个网站上工作,我们目前有一个 cookie 横幅,它在启动时显示并有一个确定按钮。 However I would to change this to give users the options to turn on/off the cookie categories they wish to be tracked.但是我想改变这一点,让用户可以选择打开/关闭他们希望跟踪的 cookie 类别。 Something like this: https://www.cookiebot.com/media/1089/cookiebot-cookie-notice.png?width=500&height=113.5670731707317像这样: https : //www.cookiebot.com/media/1089/cookiebot-cookie-notice.png?width=500&height=113.5670731707317

I am new to reactjs, I have looked online for libraries or sample but cannot find something, but I am sure they will be plenty.我是 reactjs 的新手,我在网上寻找库或示例,但找不到某些东西,但我相信它们会很多。 Anyone help or guidance will be appreciated.任何帮助或指导将不胜感激。

I have thought of adding each type of cookie to a specific group and create a function which then is called from front-end but if there is already a solution out there, it'll save time and I am worried about cross-browser/device support as well.我曾考虑将每种类型的 cookie 添加到特定组并创建一个函数,然后从前端调用该函数,但如果已经有解决方案,它将节省时间,我担心跨浏览器/设备也支持。

Thanks.谢谢。

如果您使用函数式组件,如您在 React 中描述的那样(用户能够设置和更新 cookie 首选项)实现 cookie 同意横幅的无依赖方式是使用上下文和钩子,如本文所述: https://daankauwenberg .com/react-cookie-consent/

you can use react-cookie package for this.您可以为此使用react-cookie包。

and then use relevant methods for it.然后对其使用相关的方法。 Ex, if the user agrees to save the cookie setCookie will be called.例如,如果用户同意保存cookie,setCookie 将被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM