Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. function setClientPhone(coockieName, phone, daysToExpire) {
  2.  
  3. var obj = getCookieObj(coockieName);
  4. obj.phone = phone;
  5. updateCookie(coockieName, obj, daysToExpire);
  6.  
  7. }
  8.  
  9. function updateCookie(name, value, days) {
  10. var date = new Date();
  11. date.setTime(date.getTime() + (days*24*60*60*1000));
  12. expires = "; expires=" + date.toUTCString();
  13. document.cookie = name + "=" + value + expires + "; path=/";
  14. };
  15.  
  16. function getCookieObj(name) {
  17. var val = getCookieVal(name);
  18. if (val) {
  19. return JSON.parse(val);
  20. }
  21. else {
  22. return {};
  23. }
  24. }
  25.  
  26. function getCookieVal(name) {
  27. var nameEQ = name + "=";
  28. var ca = document.cookie.split(';');
  29. for (var i = 0; i < ca.length; i++) {
  30. var c = ca[i];
  31. while (c.charAt(0) === ' ') {
  32. c = c.substring(1, c.length);
  33. }
  34. if (c.indexOf(nameEQ) === 0) {
  35. return c.substring(nameEQ.length, c.length);
  36. }
  37. }
  38. return '';
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement