FREE EU Cookie Law Script

If you haven’t already implemented the changes then we’ve put together a little bit of code to help you.

The EU Cookie Law deadline was the 26th May 2012 and if you haven’t already implemented the changes then we’ve put together a little bit of code to help you. Feel free to use this script on your site. A link back to our site would be grateful but not mandatory. Also, please do leave a message saying where and how you’ve implemented it.

Bear in mind you’ll still need to get your web developer to add this to your site as this is just the bare bones version and you’ll need to style it up a bit. If you haven’t already clicked “Accept” on the Dare to Think site then you’ll see how we’ve added a banner to the top of the site.

If you need either script added to your site or you’re unsure where to start please do get in touch for a quote.

NOTE 14/6/12: Thanks to Pete Norris of Liquid Engine as I think he’s managed to solve the mysterious reason why these scripts weren’t working in IE. I’ve changed the scripts below as well as uploaded new files for you to download

Version 1 – The user clicks “Accept” before the message is removed

This shows a message to the user and they must click the “Accept” button before the message is removed. After they click the link then a cookie is stored on their computer so the message doesn’t display again until the year 2022!! If you would like to change the cookie expiry date then change the 365*10 code below (365 is the number of days and 10 is the number of years).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
<!--
#eucookielaw { display:none }
-->
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<?php
if(!isset($_COOKIE['eucookie']))
{ ?>
<script type="text/javascript">
function SetCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+";path=/"+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
</script>
<?php } ?>
<title>EU Cookie Law Script 1</title>
</head>
<body>
<?php
if(!isset($_COOKIE['eucookie']))
{ ?>
<div id="eucookielaw" >
<p>We use cookies. By browsing our site you agree to our use of cookies.</p>
<a id="removecookie">Accept this cookie</a>
<a id="more">Find out more</a>
</div>
<script type="text/javascript">
if( document.cookie.indexOf("eucookie") ===-1 ){
$("#eucookielaw").show();
}
$("#removecookie").click(function () {
SetCookie('eucookie','eucookie',365*10)
$("#eucookielaw").remove();
});
</script>
<?php } ?>
</body>
</html>

Download version 1 of the Free EU Cookie law script now

Version 2 – The user only sees the message once

This shows a message to the user once and then stores the cookie so it is never shown again.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
<!--
#eucookielaw { display:none }
-->
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<?php
if(!isset($_COOKIE['eucookie']))
{ ?>
<script type="text/javascript">
function SetCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+";path=/"+((expiredays==null) ? "" : ";expires="+exdate.toUTCString())
}
</script>
<?php } ?>
<title>EU Cookie Law Script 2</title>
</head>
<body>
<?php
if(!isset($_COOKIE['eucookie']))
{ ?>
<div id="eucookielaw" >
<p>By browsing our site you agree to our use of cookies. You will only see this message once.</p>
<a href="#" id="more">Find out more</a>
</div>
<script type="text/javascript">
if( document.cookie.indexOf("eucookie") ===-1 ){
$("#eucookielaw").show();
SetCookie('eucookie','eucookie',365*10)
}
else {
$("#eucookielaw").remove();
}
</script>
<?php } ?>
</body>
</html>

Download version 2 the Free EU Cookie Law script now

36 replies on “FREE EU Cookie Law Script

  1. Avatar for Keith Redo Keith Redo says:

    Thanks guys! I need to get this script working on my http://www.redowebdesign.com site… I downloaded and uploaded it and now I need to figure out how to configure it.

    1. Avatar for daretothink daretothink says:

      If you follow the steps then you should be okay. Any problems just let me know.

      1. Avatar for Keith Redo Keith Redo says:

        I am not a strong JS programmer/configurer but I figured it out! Now it works great. So easy. Thank you so much!

  2. Avatar for Teresa Bowen Teresa Bowen says:

    Thank you so very much for this code. I have been struggling to find something like this for my site and this is perfect. It just works!

  3. Avatar for Guest1234 Guest1234 says:

    Hi. So where is my cookies are? Where does it store to view it?

  4. Avatar for Jacob Jacob says:

    I like this; it would be even better if the second one had a click to close button like the first one does – I can see people wanting to close it right away and not being able to do so.

    I’m trying to get such a button to work … but my JavaScript is on a par with my French …

    1. Avatar for daretothink daretothink says:

      Hi Jacob. Unfortunately I do not have any spare time at present to implement this request. You could try this script and adding a button with the class of “remove”.

          $(“.remove”).click(function () {      $(this).parent().remove();    });

  5. Avatar for Pete Pete says:

    Thanks for the code, do you have to have jQuery 1.7.2 for this to work or will it work with jQuery 1.7.1? I’ve implemented it onto my Magento site and it’s breaking my drop down navigation and AJAX layered navigation. Don’t really know anything about jQuery so don’t know how to fix it

    1. Avatar for Pete Pete says:

      It’s only breaking when I use . If I remove it to use the jQuery already on the site it doesn’t work at all. PS. I’m not the same Pete that says it doesn’t work in Internet Explorer.

      1. Avatar for Pete Pete says:

        I’ve worked it out now, jQuery wasn’t loading properly so I changed $(“eucookielaw”).show(); to jQuery(“eucookielaw”).show(); and that’s sorted it. You can see it here http://www.displaywizard.co.uk

        1. Avatar for daretothink daretothink says:

          Thanks for letting me know. Yes, I sometimes have this where sometimes I need to use $ and sometimes jQuery!

          1. Avatar for Pete Pete says:

             Yeah, something I have only just learnt 🙂 also I’ve tried this in IE8, IE9, Firefox, Google Chrome on Windows and Safari, Firefox and Google Chrome on OS X and it works on all of them. So thank you very much for the code

  6. Avatar for Pete Pete says:

    Doesn’t work in Internet Explorer

    1. Avatar for daretothink daretothink says:

      What version? What OS? Works perfectly on my Windows 7 running IE9 and then running IE8 and IE7 within.

  7. I have one at eurapart.com/c2.html or eurapart.com/php

  8. Hi, Nice script. What is the jquery include needed for?

    1. Avatar for daretothink daretothink says:

      Thanks. That’s there so the .remove and .show work. If you remove it the div will not appear.

      1. Ah great, thanks for your reply. We used the downloadable zip version and it works in IE8 but not  IE9

        1. Avatar for daretothink daretothink says:

          I’ve tested this in IE7, 8 and 9 as well as FF, Chrome and Safari on both Mac and PC. Are you sure you’re clearing your cache in IE each time you test it? Do so by going to Tools > Safety > Delete Browsing History and make sure the Cookies checkbox is checked.

          1. oh yes, definitely clearing cache, deleting cookies, etc; it just displays, but doesn’t go away. seems it is not setting the cookie, even when we have accept all cookies selected and most minimal security settings.

            1. Avatar for daretothink daretothink says:

              Hi Michael. That’s very strange. Do you have a link to which I can see this in action?

                1. Avatar for daretothink daretothink says:

                  Just tested that site on a Mac (Safari, Chrome and Firefox) and PC (IE9, IE8, IE7, Chrome, Safari, Firefox) and is working on all.

                  1. Hmm, I wonder then, I was having significant problems on windows xp and ie 8 on my machine and also on a VM on linux running xp and ie8. our windows 7 machine and ie 9 isnt working for any of the urls

                    1. Avatar for daretothink daretothink says:

                      Hmm, indeed. I don’t really know what to suggest Michael. I’m very sorry I can’t be of any further help.

            2. I’m having the same difficulty as Michael with IE9. Are you using the code as available in the download to test or the code as implemented on your site?
              eurapart.com/c2.php or eurapart.com/c2.html neither work with IE9

              1. Avatar for daretothink daretothink says:

                Hi John. Both of those are working in IE9 on my machine. I’m using Parallels Desktop on my Mac to run Windows 7 with IE9 installed.

  9. Avatar for Inkwnothing Inkwnothing says:

    Sorry, but neither work using IE

    1. Avatar for daretothink daretothink says:

      Hi. Thanks for pointing that out. It appears that when you copy and pasted the script direct from the site that it somehow broke the script. Very strange and it did the same for me. I’ve now added downloadable files instead. Please try again and let me know how you get on.

    2. Avatar for daretothink daretothink says:

      I’ve now also fixed the code above so you can either download it or simply copy. Let me know how you get on.

      1. Avatar for Dave Dave says:

        I found this through Google and its a great piece of code that worked well, simple but effective

Leave a Reply

Your email address will not be published. Required fields are marked *