EU Cookie Law in Belgium

On 21 June 2012 the Belgian Parliament approved a new set of cookie rules.  In short, from now on, all websites have to inform their consumers they are using cookies and explain to them how to manage these cookies. You can read more about it here.

This law simply means you have to create a message on your website where everybody can see it and hide when they implicitly consent.
For SharePoint you can implement this in your masterpage. I’ve done this a few times, quit simple actually, just some javascript.

JavaScript in de .master

<script type="text/javascript">

/*Register the jquery and our custom javascript*/

if(typeof($) != 'function')
{
  var jqueryScript = '<asp:Literal runat="server" Text="<%$SPUrl:~SiteCollection/Style Library/Scripts/jquery-1.7.2.min.js %>" __designer:Preview="/Style Library/Scripts/jquery-1.7.2.min.js" __designer:Values="&lt;P N='Text' Bound='True' T='SPUrl:~SiteCollection/Style Library/Scripts/jquery-1.7.2.min.js' /&gt;&lt;P N='ID' T='ctl19' /&gt;&lt;P N='Page' ID='1' /&gt;&lt;P N='TemplateControl' ID='2' /&gt;&lt;P N='AppRelativeTemplateSourceDirectory' R='-1' /&gt;"/>';
  document.write('<script type="text/javascript" src="' + jqueryScript + '"><\/script>');
}
if(typeof(EUCookie_Init) == 'undefined')
{
  var cookieScript = '<asp:Literal runat="server" Text="<%$SPUrl:~SiteCollection/Style Library/Scripts/cookie.custom.min.js %>" __designer:Preview="/Style Library/Scripts/cookie.custom.min.js" __designer:Values="&lt;P N='Text' Bound='True' T='SPUrl:~SiteCollection/Style Library/Scripts/cookie.custom.min.js' /&gt;&lt;P N='ID' T='ctl20' /&gt;&lt;P N='Page' ID='1' /&gt;&lt;P N='TemplateControl' ID='2' /&gt;&lt;P N='AppRelativeTemplateSourceDirectory' R='-1' /&gt;"/>';
  document.write('<script type="text/javascript" src="' + cookieScript + '"><\/script>');
}
/*I don’t want to show my cookie notification in a dialog or application page, therefore check if the url contains “IsDlg=1” */
if (!window.location.search.match("[?&]IsDlg=1"))   
        {
        attach(window, 'load', init);
        function attach(elm, event, callback) 
        { 
            if (elm.addEventListener) 
            { 
                window.addEventListener(event, callback, false);
            } 
            else if (elm.attachEvent) 
            {
                elm.attachEvent('on' + event, callback);
            }
        }
        function init()
        { /*Constructor of the EUCookie*/
            EUCookie_Init("Dummie", 1, "/Pages/Terms-and-conditions.aspx");
        }        
}
</script>



 


cookie.custom.min.js


function EUCookie_Init(name, days, policyURL) {
    _name = name;
    _days = days;
    _policyURL = policyURL;
    checkCookie();
}
function setCookie() {
    if (_days) {
        var date = new Date();
        date.setTime(date.getTime() + (_days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else 
    {
        var expires = "";
    }
 
    document.cookie = _name + "=" + _value + expires + "; path=/;";
    var footer = document.getElementById("cookie-opt-in-footer");
    footer.style.display = "none";
 
    var buttonAgree = document.getElementById("cookie-opt-in-button");
    buttonAgree.style.display = "none";
}
 
function getCookie(e) {
    var t = document.cookie.indexOf(e + "="), n = t + e.length + 1, r;
    return !t && e !== document.cookie.substring(0, e.length) ? null : t === -1 ? null : (r = document.cookie.indexOf(";", n), r === -1 && (r = document.cookie.length), unescape(document.cookie.substring(n, r)))
}
 
function checkCookie() {
    var result = getCookie(_name);
    if (result != _value) {
        //show div
        var htmlbody = document.getElementsByTagName("body")[0];
        var div = document.createElement("div");
        div.id = "layover-target";
        htmlbody.appendChild(div);
        document.getElementById("layover-target").innerHTML = "<div id='cookie-opt-in-footer' style='display:none'><div id='cookie-opt-in-message'>In order to let this site work properly, we use cookies. If you use our site, we assume you agree with our <a href='" + _policyURL + "' target='_blank' id='opt-in-link-b'>cookie policy</a>.</div></div><div class='cookie-opt-out-close' id='cookie-opt-in-button'>I Agree<div id='close-cookie-opt-out'>X</div></div>";
        var buttonAgree = document.getElementById("cookie-opt-in-button");
        var footer = document.getElementById("cookie-opt-in-footer");
        buttonAgree.onclick = setCookie;        
        footer.style.display = "block";
        var link = document.getElementById("opt-in-link-b");
        var buttonClose = document.getElementById("close-cookie-opt-out");
        var message = document.getElementById("cookie-opt-in-message");
        footer.style.bottom = "0px"; footer.style.width = "100%";
        footer.style.backgroundColor = "#000000";
        footer.style.minHeight = "25px";
        footer.style.position = "fixed"; footer.style.color = "#FFFFFF";
        footer.style.textAlign = "center"; footer.style.padding = "7px 0 0 0"; footer.style.fontSize = "12px"; footer.style.opacity = "0.8"; footer.style.filter = "alpha(opacity=80)"; footer.style.zIndex = "9999";
        link.style.color = "#FFFFFF"; link.style.textDecoration = "underline";
        buttonAgree.style.height = "16px"; buttonAgree.style.width = "60px"; buttonAgree.style.border = "1px solid #FFFFFF"; buttonAgree.style.padding = "2px 10px 2px 5px"; buttonAgree.style.marginRight = "5px"; buttonAgree.style.cursor = "pointer"; buttonAgree.style.position = "fixed"; buttonAgree.style.bottom = "5px"; buttonAgree.style.zIndex = "9999"; buttonAgree.style.right = "0"; buttonAgree.style.color = "#FFFFFF"; buttonAgree.style.textAlign = "left";
        buttonClose.style.border = "1px solid #FFFFFF"; buttonClose.style.fontSize = "8px"; buttonClose.style.padding = "0 1px 0 3px"; buttonClose.style.margin = "1px 0 2px 3px"; buttonClose.style.position = "fixed"; buttonClose.style.bottom = "8px"; buttonClose.style.right = "10px"; buttonClose.style.width = "8px";
        message.style.marginRight = "100px";
    }
    else {
        //don't show div
    }
}
 
var _name;
var _value = "cookieAgree";
var _days;
var _policyURL;
 

Reacties

Populaire posts