Advertisement
yur15t

get/set UTF-8 cookie

Aug 2nd, 2014
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getCookie(name) {
  2.     var matches = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"));
  3.     return matches ? decodeURIComponent(unescape(matches[1])) : undefined;
  4. }
  5. function setCookie(name, value, expires) {  
  6.     document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
  7. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement