3

Searches seemingly only turn up solutions that use JavaScript. I want to present a Cookie consent message that is visible even when the visitor is using a scriptblocker, so I am wondering if this may be done with CSS and HTML, without any JS at all?

The visible part is one thing. Then there is the question of interacting with it: Some links looking like buttons may suffice to send the visitor to the Privacy Policy page, etc.

However, what to use to register the Consent, which means setting/changing a cookie? Can that be done while the scriptblocker is actively blocking any scripts? (using just HTML..?)

As a consequence, a page reload triggered by a click would be acceptable.

matronator
  • 465
  • 6
  • 13
Leeteq XV
  • 31
  • 3
  • 1
    You can send any data you like to your server using just a simply plain HTML form … and then set your consent cookie from the server side. – 04FS May 03 '19 at 11:55

2 Answers2

1

I'm pretty sure it's not possible to set Cookies/Sessions/etc with only HTML and CSS. Without JavaScript, you're going to have to use some server-side language. As 04FS said in the comment, you can send the form data with just HTML to the server and do what you need with it there.

A quick and somewhat "dirty" solution could be easily implemented in PHP which is supported by pretty much any hosting provider and it can be embedded in HTML effortlessly (After all, that's what it was originally made for).

Here's a very simple example of how you might go about it:

Remember to rename your whatever.html to whatever.php so you can actually use PHP.

<!-- index.php -->
<html>
<body>

  <div id="dialog" style="<?php isset($_COOKIE['hideDialog']) ? echo 'display: none;' : echo 'display: block;'; ?>">
    <p>Confirm to hide this message</p>
    <form action="saveCookie.php" method="get">
        <input type="submit" value="Confirm">
    </form>
  </div>

</body>
</html>

And the script file you'd be calling with your form:

<?php

// saveCookie.php

setcookie('hideDialog', 'true', strtotime('+ 30 days'), "/");

Dharman
  • 30,962
  • 25
  • 85
  • 135
matronator
  • 465
  • 6
  • 13
-1

Yes, although it won't have the same functionality as JS, you can accomplish a warning / pop-up message by doing the same thing I did here with the yellow Phone Number notification.

Look at the YELLOW PHONE NUMBER BOX in the Packages Section.

The site is written in pure HTML/CSS/Vanilla JS, so you can inspect the page to see how it's done. The little snippet you're interested in is all HTML/CSS. Quite simple if that's what you're looking for. It won't be able to monitor for events like JS though, so it obviously won't have the functionality, however, you could put it in its own DIV and position it absolute so that it shows up wherever you want it to when the page is loaded.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 2
    Thanks for taking time to answer the question. Please consider including the code here in the answer rather than linking to your site and checking the markup. – tshimkus Oct 20 '19 at 12:04