Cookie Notification Bar?« Back to Questions List
How to make cookie notification bar? |
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 Cookiefunction 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 1Using Code Tag, add the JavaScript cookie code and the custom JS code to your design. Step 2Taking 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 See Layer Naming Rules for more details. Understanding the JavaScriptif(!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 3You will also need some JavaScript to set the Cookie when the close button is clicked. |
i want to create this notification in JS |
Hi, i want to create someting like this |
Hi, Give us an example of what you want to create, maybe a screenshot if possible. Also are you using JS or PHP? |
Share Your Knowledge!
Contribute to the community and help other users to benefit from your answer with experience and knowledge.