Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. //Create Cookie
  2. function createCookie(name, value, expires, path, domain) {
  3. var cookie = name + "=" + escape(value) + ";";
  4. if (expires) {
  5. // If it's a date
  6. if(expires instanceof Date) {
  7. // If it isn't a valid date
  8. if (isNaN(expires.getTime()))
  9. expires = new Date();
  10. }
  11. else
  12. expires = new Date(new Date().getTime() + parseInt(expires) * 1000 * 60 * 60 * 24);
  13.  
  14. cookie += "expires=" + expires.toGMTString() + ";";
  15. }
  16.  
  17. if (path)
  18. cookie += "path=" + path + ";";
  19. if (domain)
  20. cookie += "domain=" + domain + ";";
  21. document.cookie = cookie;
  22. }
  23.  
  24. //Delete Cookie
  25. function deleteCookie(name, path, domain) {
  26. console.log('deleting ' + name + ' cookie...');
  27. createCookie(name, "", -1, path, domain);
  28. }
  29.  
  30. //Accept Button Click - CREATE COOKIE
  31. $('#accept').click(function(e){
  32. e.preventDefault();
  33. console.log("You've accept our cookie policy!")
  34. createCookie("MyCookie", "Yummy", 2, "/", ".xyz.com");
  35. });
  36.  
  37. //Decline Button Click - DELETE COOKIE
  38. $('#decline').click(function(e){
  39. e.preventDefault();
  40. console.log("You've declined our cookie policy!");
  41. deleteCookie("myCookie", "/", ".xyz.com");
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement