cookies-banner.html 1.11 KB
Newer Older
1
<div class="cookies-banner" id="cookies-banner">
2
  <div class="container-md py-3 d-md-flex justify-content-between">
3
    <p>
4
      {{ i18n "this_website_use_cookies" }}<br>
5
      {{ i18n "using_agreeing" }} <a href="https://www.bsc.es/legal-notice">{{ i18n "privacy_notice" }}</a>.
6
7
    </p>
    <div>
8
      <button class="btn btn-primary btn--big" onclick="acceptCookies()">{{ i18n "i_agree" }}</button>
9
10
11
12
13
    </div>
  </div>
</div>

<script>
14
  const key = 'cv19dp-es-consent_v1.0'
15
16
17
18
19

  // Set path to '/' prevents reappearance of the banner when accepting cookies in any subpage different from home page.
  // Cookie will expire in 90 days = 90*60*60*24 = 7776000 seconds
  const cookie = `${key}=true; path=/; max-age=7776000`

20
21
22
23
24
25
26
27
28
29
30
  const store = (cookie) => document.cookie = cookie
  const isCookieStored = (key) => document.cookie.split(';').some((item) => item.trim().startsWith(`${key}=`))
  const banner = document.querySelector('#cookies-banner')
  const hide = (element) => element.style.display = "none"
  const acceptCookies = () => {
    store(cookie)
    hide(banner)
  }
  if (isCookieStored(key)) {
    hide(banner)
  }
31
</script>