EU Cookie Law - Cookie Consent Checker jQuery Plugin

EU law in its infinite wisdom now requires web sites to be explicit about Cookie usage.

I am not going to explore the legal rights or wrongs of these regulations. If you want more information see:

Any EU web users will by now have seen these "cookie consent" forms pop up on their favourite sites. To make it easier to add your own cookie consent checker I have put together a simple jQuery Plugin.

See the Demo.

Download the Files (zip).

How to use

In the ZIP you find everything you need.

1. Load jQuery and the 'cookieChecker.js' plugin file. ie:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="js/cookieChecker.js"></script>

2. Attach the plugin to the <body> tag.

You can do this at the bottom of the file before <body> like so:

</body>
$('body').cookieChecker();

Alternatively, if you prefer add a jQuery $(document).ready function to the <head> of the document like this:

<head>
<script>
$(document).ready(function(){
$('body').cookieChecker();
});
</script>
</head>

In either case attach the plugin to the <body> tag.

3. Change the Default Parameters

The plugin has the following optional parameters.

cookieName
Name of the cookie to be created - default name 'policyAgreed'
msgFile
The path to the HTML file to be used to hold the consent message. Create and style your own file or the edit the default 'js/cookieMsg.html'
duration
Length in years for cookie to persist - default name 3 years

For example:

$('body').cookieChecker({'cookieName':'myCookie','msgFile':'msg/myMessage.html','duration':1});
});

3. Customize the Message

To customize the message open the 'cookieMsg.html' file. Use the CSS file to format to taste.

Finally you should also put together your own cookie policy file outlining what cookies you have used. Here is an example I used.

Any comments, suggested improvements welcome.