set cookie javascript

Solutions on MaxInterview for set cookie javascript by the best coders in the world

showing results for - "set cookie javascript"
Angela
14 Oct 2017
1function setCookie(name,value,days) {
2    var expires = "";
3    if (days) {
4        var date = new Date();
5        date.setTime(date.getTime() + (days*24*60*60*1000));
6        expires = "; expires=" + date.toUTCString();
7    }
8    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
9}
10function getCookie(name) {
11    var nameEQ = name + "=";
12    var ca = document.cookie.split(';');
13    for(var i=0;i < ca.length;i++) {
14        var c = ca[i];
15        while (c.charAt(0)==' ') c = c.substring(1,c.length);
16        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
17    }
18    return null;
19}
20
21setCookie("user_email","bobthegreat@gmail.com",30); //set "user_email" cookie, expires in 30 days
22var userEmail=getCookie("user_email");//"bobthegreat@gmail.com"
Mitt
16 Mar 2017
1function setCookie(name,value,days) {
2    var expires = "";
3    if (days) {
4        var date = new Date();
5        date.setTime(date.getTime() + (days*24*60*60*1000));
6        expires = "; expires=" + date.toUTCString();
7    }
8    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
9}
10function getCookie(name) {
11    var nameEQ = name + "=";
12    var ca = document.cookie.split(';');
13    for(var i=0;i < ca.length;i++) {
14        var c = ca[i];
15        while (c.charAt(0)==' ') c = c.substring(1,c.length);
16        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
17    }
18    return null;
19}
20function eraseCookie(name) {   
21    document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
22}
23
Mathilda
10 Aug 2017
1const setCookie = (options) => {
2  const {
3    name,
4    value = '',
5    path = '/',
6    duration = 3600,
7  } = options;
8  
9  const durationMs = duration * 1000;
10  const expires =
11    new Date(Date.now() + durationMs);
12
13  document.cookie = 
14    `${name}=${escape(value)}; expires=${expires.toUTCString()}; path=${path}`;
15}
16
17const getCookie = (name, cast = String) => {
18  if (document.cookie.length == 0)
19    return;
20
21  const match = document
22    .cookie
23    .match(`${name}=(?<value>[\\w]*);?`);
24
25  if (!match)
26    return;
27
28  const value =
29    match?.groups?.value ?? '';
30
31  return cast(unescape(value));
32}
33
34const cookieExists = (name) => {
35  return getCookie(name) !== undefined;
36}
37
38const deleteCookie = (name) => {
39  setCookie({
40    name: name,
41    value: undefined,
42    duration: -1,
43  });
44}
45
46
47// Example string
48setCookie({ 
49  name: 'username',
50  value: 'dude',
51});
52
53const username = 
54  getCookie('username');
55
56
57// Example number
58setCookie({
59  name: 'count',
60  value: 100,
61  duration: 300, // 300s, 5 minutes
62});
63
64const count =
65  getCookie('count', parseInt);
66
67deleteCookie('count');
Vincent
03 Jul 2020
1For storing array inside cookie : 
2-----------------------------------
3setter : var json_str = JSON.stringify(arr); cookie.set('mycookie', json_str);
4getter : cookie.get('mycookie'); var arr = JSON.parse(json_str);
5----------------------------------------------------------------------------
6Function common for all type of variable : 
7==========================================
8let cookie = {
9            set: function(name, value) {
10                document.cookie = name+"="+value;
11            },
12            get: function(name) {
13                let nameEQ = name + "=";
14                let ca = document.cookie.split(';');
15                for( let i = 0; i < ca.length; i++ ) {
16                    let c = ca[i];
17                    while (c.charAt(0)==' ') c = c.substring(1,c.length);
18                    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
19                }
20                return null;
21            }
22        }
queries leading to this page
create cookie javascriptget cookies jshow to set cookies in javascript with the values from formusing js how do i access cookiesgetcookie function in jsinsert cookie using jsdoucment get cookieget cookie by name javascriptjavascript set and get cookiehow to set cookies in javascriptset cookie httponly javascriptjs cookie setcreate a cookie jsjs setcookie and delete cookiehow to set a site cookie in javascriptjavascript get local cookiehow to get a single cookie in jsfunction setcookie javascriptjavascript get cookie set cookiejavascript getcookieset browser cookie javascriptjavascript cookie set and getset cookie from jshow to use cookie javascriptsetcookie javascriptjavscript cookiecreate cookiesdocument cookie get setget cookies from browser javascriptjs cookie getjs read cookiejavascript read cookiecreate cookie jsjavascript get cookie functionget set cookieget cookie value in jqueryset cookies with javascriptgetcookie javascriptjs cookie set cookieget cookie from document cookiesave data in cookie javascriptgetcookies from webpage jsget cookie jqueryread cookie value jsuse cookies jsjavascript add a cookieget value from cookie javascriptjavascript get cookie objectdocument cookie getcreatecookie in jsset cookie javascriptjavascript get 2fset cookiecookie in jsjs change cookie valuehow to set cookies in browser jsadd cookie jshow to save cookies javascriptset cookie in request javascripthtml js cookiesstore cookie javascriptjavascript get cookie from response headerset js cookiesave cookies jsset cookie js consoleread cookie in javascriptjavascript save to cookie getsetcookies javascriptcookies manipulation javascriptadd cookies by javascriptuse javascript to update cookiesetcookie function in jshow to store cookie in javascriptsend cookie in js read cookie value htmlhow to create a cookie in javascriptjavascript how to set cookiejs cookiesread a cookie value in javascriptjavascripte set cookiejs get value from cookieget cookie value javascriptget value of cookie in javascriptdocument cookie add cookie javascriptjs getcookiejavascript cookie setlogin with cookies javascriptjs save data cookiejs store a cookiecookie js getdocument cookie setjavascript get cookiehow to store value in cookie using javascriptcookie en jsjavascript set cookieretrieve cookie from jsget cookie using keys i javascriptget cocki jsjavascript cookiesjavascript cookies setjavascript create cookie exampleset cookiehow to manipulate cookies using javascriptjavascript store value in cookiehow to set cookies in browser in js add cookie in javascriptjs function to set cookiejavascript read cookie valuejavascrript get cookie as jsoncookie funcions jsjavascript document cookie expirejs set a specific cookieget document cookieget cookie set cookie javascriptmaking cookies with java scriptjs cookie set and gethow to make cookies in htmlgetting cookie value in javascriptcookies set jsget cookie in jsdocument cookie add new cookiejs add a cookie that expiresget value of a cookie javascripthow to read cookies in javascripthow to get cookie keyjavascript how to create a cookiejs set cookie functionadd value to cookie javascriptset a cookie in jscode in js to create cookiesset cookie with javascript javascriptcookies jsdocument setcookieadd cookies javascriptremove cookie javascriptset cookie in jsdocument cookie javascriptsetcookies in jsjs cookie de connexionset cookie with document cookiehow to create cookies in javascriptjavascript cookies set and getjavascript setup cookiesjs get cookiecookies with javascriptset cookie in javascrit w3js set cookiessession cookie javascripthow to access cookie value request javascruothow to get the cookie value in javascriptusing cookies in javascriptjs set a cookiejs open cookiehow to set cookies javascripthow to get cookie value jsset cookies in javascriptcookies set javascriptjs get cookie by namesimple cookie javascriptjs access cookiesgetcookie function jscookies jsjs get cookie valuejavascript get from cookiessave js variable in cookiegrab cookies jsvanilla js get cookiesdocument cookiesjs document cookie setjs cookie create and getset cookie javascript w3schoolscookie in javascriptjavascrip how to get cookiehow to set cookie in javascriptjavascript get dtat from cookiecookie get javascriptread cookie strin gget first cookie javascriptget cookiejs read page cookieshow to get the document cookie javascriptjavascript read cookie by nameset cookie using javascriptjs set in cookiesdocument cookie getcookie javascriptsetcookie function javascriptget cookie value jsget browser cookies javascriptjavascript get cookie value by nameset cookie from javascriptjs store cookiehow to create cookie with javascriptjavascript to set cookiesset cookie in javascrithow to set cookie jsget item from cookie javascriptwriting a cookie with jsjavascript cookies tutorialcookie by jsjavascript cookies create and gethow to save cookies jsadd to cookie javascriptjs get cookie in a dominaaccess cookies javascripthow to get cookies in javascriptjs set and get cookiejs write to cookieget cookie from document jsjs cookie exampleset cookie browser javascriptget and set cookie in javascriptget cookie using jsget cokkieget cookie javascripthow to create cookie in javascriptget set cookie javascriptcookies javaascrpjsdom get cookiesdocument cookie 3dget cookie valueget specific cookie in javascriptjavascript readcookieget cookie by value jsget cookies javascritjs edit a cookieget current cookies javascriptjavascript cookiehow to acess cookies in jshow to get cookie value in javascriptjs get cookie et cookiejavascript get access to cookieset up cookies javascriptusing cookies jsmake a cookie htmljs setcookiestore cookies javascriptjavascript get cookie valuesave cookie javascriptjavascript cookies createjs save cookiehow to create a cookie jsjavascript get browser cookiesstore value in cookie using javascriptbrowser cookies jsset cookie in javascript functionstore a cookie using jsset cookies function in jsjs get cookiesjs set cookie domainget cookie from jsset value in cookie javascriptsetcookie in jsjs get certain cookieread varaible from cookie javascripthow to read cookie in javascriptget cooki jsjavascript get value of a cookiejava script cookieswrite cookie javascriptw3 cookiesread cookie jshow to make cookies javascriptjavascript get cookie browserjavascript add cookiefunction setcookie and get cookie in javascriptsee cookies javascriptset cookies with jqueryhow get cookie javascriptadd cookies in jsvar cookie 3d getcookie 28 cookie1 29 using javascripthow to get a cookie value with js cookjiejavascript get cookie by nameget cookie by namejs write cookiedocument cookie split 28 27 3b 27 29set cookies javascriptset tocken in cookie jshow to store a cookie jshow to set webpage as cookie javascriptscript set cookiesave cookies javascriptget cookie value in javascript by nameget cookie method for jsset cookie vanilla jsjavascript update cookiejavascript get cookiesset cookie name javascriptjavascript get cookie infodocument cookie addsetcookie javascript functionjs edit cookie valueinsert cookie javascriptjs cookiedocument cookie jsjs storing a cookie valueget information from cookie javascriptdocument cookie pathdocument cookieaccess cookies in javascriptcookies javascriptsetting cookies javascripthow to create and read cookies in javascriptjs add cookieshow to get cookiejs make cookieusing cookies in jssetting a cookie in jsmake a cookie javascriptset cookies javascript from apijs create cookieget browser cookie in javascripthow to access cookie data in plain javascriptset cookie using jscookies javascript examplejavascript console add cookieget the cookie value in javascripthow to add cookies to your website jsjavascrtip cookiehow we set cookie through jsset cookie javascrptjavascript change document cookiewhat is cookie in jsjavascript save cookiehow to save to cookies in javascriptjavascript is cookie sethow to get cookie in javascripthtlm js save in coockiesstore cookie jsdocument get cookieadd browser cookie variable javascriptsetcookie jsjavascript cokkiehow to set and read cookies in javascriptjavascript cookie functionsget cookies value using javascriptcreate cookies in jsget cookie js by nameget page cookie jssetting a cookie in javascriptjavascrip cookie examplehow to get cookies value in javascriptcookie set and get javascriptjs setcookie functionset cookies in javasctipthow to use cookies in javascriptjavascript set cookie for 1 hourdocuemnt cookie to ser cookiecreate a cookie in javascriptset and get cookie in javascriptdocument cookie valuejavascript add cookiesget cookie jsjavascript create a cookiejs cookie codecookie example set cookie get cookiehow to get cookie in jsget cookie js valuejs how to access a cookiejavascript check cookiejavascript write cookiegetcookieget cookies javascriptdocument cookie deletecookies scriptreact cookie set expiresget cookie content javascriptset and get cookies js 2020how to access a particular document cookiehow we set cookie in jsgetcookies jshow to check cookie in jsset a cookie in javascriptcreate cookie in javascript w3schoolsjavascript get a cookiehow to use cookies in jsjavascript create cookiemake a call to check the cookie javascriptsave cookie in javascripthow to get cookie value in jshow to make cookie htmlhow to add the cookies in htmljs get cookie functionget cookie string javasc riptcreate new cookie javascripthow to add cookie in javascriptget cookie with javascriptsetcookie javasset sample cookie jssave html data in cookiesjs read cookiesjavascript generate cookiesetcooking jscreate cookie in jsadd cookie from jshow to get cookies from browser in javascriptset value in cookieset cookie htmlset a cookiecookies html jsjavascript document cookie getset cookie using document cookiejs set and retrive cookieset cookie jsset cookie on browserif document cookie is setget cookie jsjs how to set cookie pathjavascript read a cookiejs get cookie itemcockie in jscookies htmljavascript make cookieset cookie and set cookie jsget login cookie with javascriptjs document cookiejavascript set cookie pathjavascript set expiring cookiestoring cookies in jsadd a cookie in jsjavascript write and read cookiejavascript create cookiesset cookie with javascriptsave value in cookie javascriptcookies in javascriptjavascript cookie setupjs read cookie valuejavascript set get cookiejs add new cookieget a cookie in javascriptjscookieset a cookie javascriptjava script save cookiecheck cookies and set cookie jshow to set and get cookie in havscriptjavascript add cookie to requestjs read specific cookiehtml check cookiehow to store http cookie javascriptcookie get functiongenerate cookieshow to make a cookie in jshow to add a cookie from jsget cookie value in javascriptjavascrip set get cookieget data from cookie javascriptjs cookiecookie set in javascriptjavascript change cookie valuecookie save by javascriptget cookies with jsjavascript setcookieadd values to cookies javascriptget cookies in javascriptupdate cookie javascripthow to add cookies jsadd a cookie javascriptedit cookie value jsdocument cookie javascriptget cookie in javascriptcookie gethow to add cookies in javascriptcookis jshow to get specific cookie value in javascriptjs cookiesjavascript read cookisset cookie in javascriptset cookies htmljavascript get value form cookieshow to edit a cookie in jsstore cookie in javascriptjs create a cookie exampleset cookie by javascriptmake new cookie jsjavascript access cookiesjs getcookie and setcookieprint cookie client sidecookies jscheck cookies in javascriptcookie javascript setsave variable in cookie javascripthow to set and get cookiestore cookies in jshow to accept cookie before entering site using javascriptgetcookie value javascriptwhat are cookies in javascriptset cookie value javascriptjquery get cookieread the cookie in jsset cookies on javascript pageget data from cookiecreate cookie in javascriptcookies js cookiecookie set and getget one cookie javascriptcreate cookie document javascriptjs check cookiejs read write cookieget value from document cookieread cookie javascripthow to write cookies with client javascripthow to get document cookie value in jsjs cookiedocument get cookie by namevanilla javascript set cookieread cookiecreate cooki jsget cookie with jsjavascrit read write cookiewrite and read cookie in javascriptset javascript cookiejs set cookiejavascript set cookie valuejavascript get and set cookiesjs add set cookie save to cookie javascriptjavascript set temporary cookiejs add cookiemodify cookie jsset and get cookie function hjscookie jschange cookie javascriptjs get ookiecookie jsset cookie javascript consolejs get 2fset cookiecookies create javascriptget cookie javascript by nameassign cookies in javascriptjavscript set cookieget cookiesjavascript how to set a cookiehow to add a cookie in javascriptset data in cookies javascriptget cookie using javascriptjs to get cookieset get cookie javascripthow to get website cookies with codeadd cookie javascriptjavascript set cookiesfind cookie javascriptjavascript history set and get cookie valuejavascript get and set cookieget cookie from javascriptread cookie value javascripthow to set a cookiehow to get info from cookies javascriptjava script get and set cookiessetcookies function jsset cookie js cookie min jsjavascript find cookie by namejavascrpt cookieread cookie value in javascriptget a cookie value in javascriptcookie functions jsget js cookiejs create new cookiejava script get cookieset cookie by passing id using javascriptnew cookie javascripthow to set a cookie in javascriptjavascript crear cookiecheck value of a cookie javascriptset cookies in jsadd cookie using jscookies in jsadd cookie in jsgetcookie jsjavascript cookies csshow to get the value of a specific cookie in javascriptjavascript access cookie by namejavascript cookies to store username and password using javascriptset cookies jsusing document cookiesave cookie in browser javascriptprint cookies jsset cookie javascript