Implementing a 'Cookie Disclaimer' in Phoenix 1.3

I am new to phoenix.
Like to implement a Cookie Disclaimer on my webpage, popping up at the bottom when visiting.
In normal html is easy:

head

pic CDN for css and js

window.addEventListener("load", function(){
window.cookieconsent.initialise({
  "palette": {
    "popup": {
      "background": "#000"
    },
    "button": {
      "background": "#f1d600"
    }
  }
})});

But this seems to not work in phx!
CDN not allowed? … put code to different place?

How to in phoenix 1.3 ?
Thanks for advice

What are the errors that you are getting with the “html” method?

A bit off-topic, but with the upcoming GDPR changes, it might be safer to not collect unnecessary info about the users (which is the only time a “cookie disclaimer” is required).

No errors… just nothing…
Well to new EU rights… we need such Disclaimer…
CDN Js is loaded

You’d need more than that, I’m afraid.

No errors… just nothing…

Can you post some code that you used which didn’t work?

<head>

<title>Title</title>
<link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>">

<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
  "palette": {
    "popup": {
      "background": "#000"
    },
    "button": {
      "background": "#f1d600"
    }
  }
})});
</script>

also tried to place the code at the bottom:
<script src="<%= static_path(@conn, “/js/app.js”) %>">

Can you check your browser’s console and see if there are any errors?

Sorry for an off-topic again, but you should probably use a sha checksum for the stuff sent to the browser from a cdn with a fallback to your own server.

1 Like

Well also downloaded the code an placed it locally…no success…

No errors in console/dev tools… Thanks so far…

Any errors in the browser’s console?

What if you use https in href and src?

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>

instead of

<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>

Also try inspecting the final html in browser and see if anything is off.

My fault…
Seems that there is a function in the script which checks weather it was already clicked ‘ok.’. When I delete the history in the browser it works…

What a joke… sorry