Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function setCookie(name, value, days=0, hours=0, minutes=0) {
  2. const milliseconds = ((days*24+hours)*60+minutes)*60*1000,
  3. expire = new Date(Date.now()+milliseconds)
  4. document.cookie =
  5. name+'='+value+'; path=/; expires='+expire.toUTCString()
  6. return value
  7. }
  8.  
  9. function getCookie(name) {
  10. const matches = document.cookie.match(new RegExp('(?:^|; )'+
  11. name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,'\\$1')+'=([^;]*)'));
  12. return matches? decodeURIComponent(matches[1]) : undefined;
  13. }
  14.  
  15. delCookie = name=> name? setCookie(name,'',-1) :
  16. document.cookie.split(";").forEach(c=> document.cookie = c.replace(/^ +/,'')
  17. .replace(/=.*/,"=;expires="+ new Date().toUTCString() +";path=/"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement