Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create Cookie
- function createCookie(name, value, expires, path, domain) {
- var cookie = name + "=" + escape(value) + ";";
- if (expires) {
- // If it's a date
- if(expires instanceof Date) {
- // If it isn't a valid date
- if (isNaN(expires.getTime()))
- expires = new Date();
- }
- else
- expires = new Date(new Date().getTime() + parseInt(expires) * 1000 * 60 * 60 * 24);
- cookie += "expires=" + expires.toGMTString() + ";";
- }
- if (path)
- cookie += "path=" + path + ";";
- if (domain)
- cookie += "domain=" + domain + ";";
- document.cookie = cookie;
- }
- //Delete Cookie
- function deleteCookie(name, path, domain) {
- console.log('deleting ' + name + ' cookie...');
- createCookie(name, "", -1, path, domain);
- }
- //Accept Button Click - CREATE COOKIE
- $('#accept').click(function(e){
- e.preventDefault();
- console.log("You've accept our cookie policy!")
- createCookie("MyCookie", "Yummy", 2, "/", ".xyz.com");
- });
- //Decline Button Click - DELETE COOKIE
- $('#decline').click(function(e){
- e.preventDefault();
- console.log("You've declined our cookie policy!");
- deleteCookie("myCookie", "/", ".xyz.com");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement