10 examples of 'jquery get cookie value' in JavaScript

Every line of 'jquery get cookie value' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
53function getCookie(name) {
54 var re = new RegExp(name + "=([^;]+)");
55 var value = re.exec(document.cookie);
56 return (value != null) ? unescape(value[1]) : null;
57}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

1847function Get_Cookie(name) {
1848
1849 var start = document.cookie.indexOf(name + "=");
1850 var len = start + name.length + 1;
1851 if ((!start) &&
1852(name != document.cookie.substring(0, name.length))) {
1853 return null;
1854 }
1855 if (start == -1) return null;
1856 var end = document.cookie.indexOf(";", len);
1857 if (end == -1) end = document.cookie.length;
1858 return unescape(document.cookie.substring(len, end));
1859 }
23function get_cookie (key) {
24 var i = document.cookie.indexOf (key+'=');
25 if (i < 0) {
26 return;
27 }
28
29 i += key.length + 1;
30
31 var e = document.cookie.indexOf(';', i);
32 if (e < 0) {
33 e = document.cookie.length;
34 }
35
36 return unescape (document.cookie.substring (i, e));
37}
37function readCookie(name) {
38 var nameEQ = name + "=";
39 var ca = document.cookie.split(';');
40 for(var i=0;i < ca.length;i++) {
41 var c = ca[i];
42 while (c.charAt(0)==' ') c = c.substring(1,c.length);
43 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
44 }
45 return null;
46 }
14function readCookie(name) {
15 var nameEQ = name + "=";
16 var ca = document.cookie.split(';');
17 for (var i = 0; i < ca.length; i++) {
18 var c = ca[i];
19 while (c.charAt(0) == ' ') c = c.substring(1, c.length);
20 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
21 }
22 return null;
23}
22function get_cookie(Name) {
23 var search = Name + "="
24 var returnvalue = "";
25 if (document.cookie.length > 0) {
26 offset = document.cookie.indexOf(search)
27 if (offset != -1) { // if cookie exists
28 offset += search.length
29 // set index of beginning of value
30 end = document.cookie.indexOf(";", offset);
31 // set index of end of cookie value
32 if (end == -1)
33 end = document.cookie.length;
34 returnvalue=unescape(document.cookie.substring(offset, end))
35 }
36 }
37 return returnvalue;
38}
26function get_cookie(Name, CookieStr="") {
27 var search = Name + "="
28 var returnvalue = "";
29 if (CookieStr.length > 0) {
30 var sd = CookieStr.indexOf(search);
31 if (sd!= -1) {
32 sd += search.length;
33 var end = CookieStr.indexOf(";", sd);
34 if (end == -1){
35 end = CookieStr.length;
36 }
37 returnvalue = window.unescape(CookieStr.substring(sd, end));
38 }
39 }
40 return returnvalue;
41}
22function getCookie(cookieName) {
23 var name = cookieName + "=";
24 var ca = document.cookie.split(';');
25 for (var i = 0; i < ca.length; i++) {
26 var c = ca[i];
27 while (c.charAt(0) === ' ') c = c.substring(1);
28 if (c.indexOf(name) !== -1) return c.substring(name.length, c.length);
29 }
30 return null;
31}
39function cookie(name) {
40 var cookieValue = null;
41 if (document.cookie && document.cookie != '') {
42 var cookies = document.cookie.split(';');
43 for (var i = 0; i < cookies.length; i++) {
44 var cookie = $.trim(cookies[i]);
45 // Does this cookie string begin with the name we want?
46 if (cookie.substring(0, name.length + 1) == (name + '=')) {
47 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
48 break;
49 }
50 }
51 }
52 return cookieValue;
53}
283function cookie(key) {
284 // read
285 var decode = function(s) {return decodeURIComponent(s.replace(/\+/g, ' '));}
286 var converted = function(s) {
287 if (s.indexOf('"') === 0) {
288 s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
289 }
290 return s;
291 }
292 var cookies = document.cookie.split('; ');
293 var result = key ? undefined : {};
294 for (var i = 0, l = cookies.length; i < l; i++) {
295 var parts = cookies[i].split('=');
296 var name = decode(parts.shift());
297 var cookie = decode(parts.join('='));
298 if (key && key === name) {
299 result = converted(cookie);
300 break;
301 }
302 if (!key && parts.length) {
303 result[name] = converted(cookie);
304 }
305 }
306 return result;
307};

Related snippets