JAVASCRIPT   18

getCookie

Guest on 13th June 2022 04:49:20 PM

  1. function getCookie(cname) {
  2.     var name = cname + "=";
  3.     var decodedCookie = decodeURIComponent(document.cookie);
  4.     var ca = decodedCookie.split(';');
  5.     for(var i = 0; i <ca.length; i++) {
  6.         var c = ca[i];
  7.         while (c.charAt(0) == ' ') {
  8.             c = c.substring(1);
  9.         }
  10.         if (c.indexOf(name) == 0) {
  11.             return c.substring(name.length, c.length);
  12.         }
  13.     }
  14.     return "";
  15. }

Raw Paste


Login or Register to edit or fork this paste. It's free.