Get started with Cookies.js CDN

UNLICENSE licensed

Lightweight library: Cookies.js handles HTTP cookies in web development.

Tags:
  • javascript
  • cookies

Stable version

Copied!

How to start using Cookies.js CDN


<!DOCTYPE html>
<html>
<head>
    <title>Get started with Cookies.js CDN - cdnhub.io</title>
    <script src="https://cdn.cdnhub.io/Cookies.js/1.2.3/cookies.min.js"></script>
</head>
<body>
    <button id="setCookie">Set Cookie</button>
    <button id="getCookie">Get Cookie</button>
    <button id="deleteCookie">Delete Cookie</button>

    <script>
        const setCookieBtn = document.getElementById('setCookie');
        const getCookieBtn = document.getElementById('getCookie');
        const deleteCookieBtn = document.getElementById('deleteCookie');

        Cookies.config({ expires: 30 }); // Set cookie expiration to 30 days

        setCookieBtn.addEventListener('click', () => {
            Cookies.set('myCookie', 'value');
        });

        getCookieBtn.addEventListener('click', () => {
            const cookieValue = Cookies.get('myCookie');
            console.log('Cookie value:', cookieValue);
        });

        deleteCookieBtn.addEventListener('click', () => {
            Cookies.delete('myCookie');
        });
    </script>
</body>
</html>

All versions