Starting on May 26th 2012 sites for any organisation based within the UK (even if their site is hosted overseas) must seek consent to store cookies on a user’s computer, or device. Failure to comply could result in a fine up to £500,000.

The idea is simple, a piece of JavaScript that can be thrown into any page, that can be used to automatically show the above banner to new visitors to check that you are allowed to store cookies. The ability is then in place so that you can simply check what stage of cookies have been accepted with the following line:

    There are 4 possible returned values:

  1. The user has actively opted out of all cookies on the site. Shows the red notification.
  2. The user has seen a warning about cookies, but neither accepted nor declined, this is classed as inferred acception. Shows the blue notification.
  3. The user has accepted all cookies to the site. Shows the green notification.
  4. The user’s first visit to the site, no cookies accepted or declined. Shows the yellow notifcation.

You should only store/use cookies if the above returns either 1 or 2. Also, the user is able to close the prompt that appears, and by them doing so it will show an icon in the bottom left hand corner of the page that they can click on for more information.

The javascript file is available to download either on Github or here.

Using it around any block of code that stores cookies is as simple as doing this:

if(cPrompt.checkCookie() == 1 || cPrompt.checkCookie() == 2){
       Cookie Storing Code Here

There are three settings you can change/enable. The ability to hide the whole cookie prompt if the user accepts cookies on the site:

cPrompt.hideOnAccept = true;

the ability to keep the prompt minimised to the bottome left of the page at all times:

cPrompt.minimisePrompt = true;

the option to specify a URL to a cookie policy on your site, this can be done by using the following line of code:

cPrompt.cookieLink = 'http://mycookiepolicy.com/me.html';