cookie-universal-ssr

In this example below you will see how to do a cookie-universal-ssr with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by microcipcip, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright microcipcip ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>cookie-universal-ssr</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <button class="add">Add cookie</button>
<button class="remove">remove cookie</button>

<h2>Result: <span class="result"></span></h2>
  <script src='https://unpkg.com/cookie-universal@1.0.13/dist/cookie-universal.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/microcipcip/cookie-universal-ssr-xYgayz */
body {
  padding: 40px;
}


/*Downloaded from https://www.codeseek.co/microcipcip/cookie-universal-ssr-xYgayz */
const cookies = Cookie()

const $addBtn = document.querySelector('.add')
const $remBtn = document.querySelector('.remove')
const $res = document.querySelector('.result')

$addBtn.addEventListener('click', () => {
    cookies.set('hello', 'helloThere')
    $res.innerHTML = cookies.get('hello')
})

$remBtn.addEventListener('click', () => {
    cookies.remove('hello')
    $res.innerHTML = cookies.get('hello')
})

Comments