Cookie Notification Bar?« Back to Questions List

How to make cookie notification bar?

Added May 12, 2017 9:43 pm

Do you have the right answer? If you do other users will benefit from your contribution, share your knowledge with the community!

Hi,

This is easy to do with a few considerations. We are assuming you have code to capture a cookie, if not you can use the following code:

JavaScirpt Cookie

function setCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return false;
}
function delCookie(name) {
    createCookie(name,"",-1);
}

Custom JS for Cookie

/*
 * The following code will show/hide
 * the cookie bar
 */
if(!getCookie('cookieNotice')){
    setCookie('cookieNotice',true);
}else{
    document.getElementById('cookie_notice').style['display'] = false;
}

Step 1

Using Code Tag, add the JavaScript cookie code and the custom JS code to your design.

Step 2

Taking note of your folder name (the main folder for your cookie notice design), you will need to add a small script to control the folder display state, E.g. If your folder name is "Cookie Notice", then your JavaScript code must reference "cookie_notice".

See Layer Naming Rules for more details.

Understanding the JavaScript

if(!getCookie('cookieNotice')){
    setCookie('cookieNotice',true);
}else{
    document.getElementById('cookie_notice').style['display'] = false;
}

Here you are checking if you have already set a cooke notice to to hide the bar, (a) if not set, then set - simple; (b) if set, hide the bar.

Step 3

You will also need some JavaScript to set the Cookie when the close button is clicked.

Answer by admin
Answered On May 14, 2017 5:12 pm #

i want to create this  notification in JS

Answered On May 13, 2017 8:15 pm #

Hi, i want to create someting like this

Answered On May 13, 2017 8:13 pm #

Hi,

Give us an example of what you want to create, maybe a screenshot if possible. Also are you using JS or PHP?

Answer by admin
Answered On May 12, 2017 10:25 pm #
Looking for another answer? View other questions in General or get premium support for guaranteed results.
Asked by kar_kie★★★
1380 views
4 answers
Last Answered 7 years ago by admin

Categories

Recent Answers

asked by Sander
asked by bps9191980
asked by admin
asked by anup-sarkar
asked by originalife07
asked by yudhis
asked by lafejol
asked by lafejol
asked by rihabbenhmida
asked by zaineb khiari
asked by nmax
asked by shanrt
asked by Ali Sodikin
asked by indian
[+] View All Recent Questions

Share Your Knowledge!

Contribute to the community and help other users to benefit from your answer with experience and knowledge.