Return to Solutions Overview <-

How to use JavaScript Cookies in Webflow

Put this script as one of your first scripts in the Head Code section of your project. This is a nice little library that allows you to use the native javascript cookie feature in a secure manner.

(Still under development as of March 15th 2023)

<!-- Cookie JS -->
<script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js"></script>

Put this script as one of your first scripts in the Head Code section of your project.
This is a nice little library that allows you to use the native javascript cookie feature.

You can learn more about all the functionality here: js-cookie GitHub.


Here are some common use cases:

/* Create an expiring cookie, valid to the path of the current page: */
Cookies.set('name', 'value', { expires: 7, path: '' })

/* Read cookie: */
Cookies.get('name') // => 'value'
Cookies.get('nothing') // => undefined

/* Delete cookie: */
Cookies.remove('name')

You want to use local storage instead of cookies? Learn more here:


- https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
- https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

Common commands are:

/* The following snippet accesses the current domain's local Storage object and adds a data item to it using Storage.setItem(). */
localStorage.setItem('myCat', 'Tom')

/* The syntax for reading the localStorage item is as follows: */
const cat = localStorage.getItem('myCat')

/* The syntax for removing the localStorage item is as follows: */
localStorage.removeItem('myCat')

/* The syntax for removing all the localStorage items is as follows: */
localStorage.clear()

FAQs

You still have an open question about BMG.studio and how we operate. Chances are good that you will find what you are looking for here:

Why does this FAQ exist?

Well. As of Wednesday, March 15th 2023, I think this component looks really cool.

Can I clone this FAQ component?

Yes. Yes you can. You can do so -> here <-

Still have questions?

It's okay to reach out. Use either email or our calendar tool