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>
36 replies on “FREE EU Cookie Law Script”
Leave a Reply
-
HTML email signature in Apple Mail
Step by step guide on how to add an HTML signature to Apple Mail.
-
Secure your WordPress Blog
A guide to securing your WordPress website.
-
Remove the shadow from Mac Screen Grabs
How to remove the shadow from Apple Screengrabs.
-
10 Useful Sites for Web Developers
Some useful websites for web developers.
-
3 FREE Apps to protect your PC
A few free apps to help you protect your PC.
-
Web Browsing Tips #1: Find in Page
Find copy in page in a web page.
-
Web Browsing Tips #2: Tabbed Windows
Using tabbed windows in your web browser.
-
Web Browsing Tips #3: Keyboard Shortcuts
Some web browsing keyboard shortcuts.
-
Redirect your site the Search Engine Friendly way
Using a 301 redirect is important when you change your website URL or web page URL.
-
Remove the WordPress Meta Tag from your Blog
Remove the WordPress meta tag from your WordPress site with this small function.
-
Stay secure, use more than one password
We need passwords for everything, but how can we stay secure and have multiple passwords without having to remember them all.
-
Forward your emails to one address
Find out how, using cPanel, you can forward your emails to one email address.
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.
If you follow the steps then you should be okay. Any problems just let me know.
I am not a strong JS programmer/configurer but I figured it out! Now it works great. So easy. Thank you so much!
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!
Hi. So where is my cookies are? Where does it store to view it?
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 …
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(); });
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
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.
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
Thanks for letting me know. Yes, I sometimes have this where sometimes I need to use $ and sometimes jQuery!
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
Doesn’t work in Internet Explorer
What version? What OS? Works perfectly on my Windows 7 running IE9 and then running IE8 and IE7 within.
I have one at eurapart.com/c2.html or eurapart.com/php
Hi, Nice script. What is the jquery include needed for?
Thanks. That’s there so the .remove and .show work. If you remove it the div will not appear.
Ah great, thanks for your reply. We used the downloadable zip version and it works in IE8 but not IE9
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.
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.
Hi Michael. That’s very strange. Do you have a link to which I can see this in action?
Hi Yes, http://wilddogdesign.co.uk
Just tested that site on a Mac (Safari, Chrome and Firefox) and PC (IE9, IE8, IE7, Chrome, Safari, Firefox) and is working on all.
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
Hmm, indeed. I don’t really know what to suggest Michael. I’m very sorry I can’t be of any further help.
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
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.
Sorry, but neither work using IE
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.
I’ve now also fixed the code above so you can either download it or simply copy. Let me know how you get on.
I found this through Google and its a great piece of code that worked well, simple but effective