10 examples of 'javascript setcookie' in JavaScript

Every line of 'javascript setcookie' 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
71function SetCookie(key, val) {
72 var d = new Date();
73 d.setTime(d.getTime()+(365*24*60*60*1000));
74 try {
75 document.cookie =
76 key + "=" + escape(val) + "; expires="+ d.toGMTString() + "; path=/";
77 } catch (e) {}
78}
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

5function SetCookie(cookieName, cookieValue, nDays) {
6 var today = new Date();
7 var expire = new Date();
8 if (nDays == null || nDays==0)
9 nDays=1;
10 expire.setTime(today.getTime() + 3600000 * 24 * nDays);
11 document.cookie = cookieName + "=" + escape(cookieValue) +
12 ";expires=" + expire.toGMTString();
13}
32export function setCookie(cName, value, expiredays) {
33 if (expiredays > 0 && expiredays !== '100') {
34 let exdate = new Date();
35 exdate.setDate(exdate.getDate() + expiredays);
36 document.cookie =
37 cName +
38 '=' +
39 escape(value) +
40 (expiredays == null ? '' : ';expires=' + exdate.toGMTString());
41 }
42 if (expiredays === '100') {
43 let exdate = new Date('2118-01-01 00:00:00');
44 document.cookie =
45 cName +
46 '=' +
47 escape(value) +
48 (expiredays == null ? '' : ';expires=' + exdate.toGMTString());
49 }
50}
160function setCookie(c_name, value, expiredays) {
161 var exdate = new Date();
162 exdate.setDate( exdate.getDate() + expiredays )
163 document.cookie = c_name + "=" + escape(value)
164 + ( (expiredays == null) ? "" : ";expires=" + exdate.toGMTString() );
165}
27function setCookie(c_name,value,expiredays){
28 var exdate=new Date();
29 exdate.setDate(exdate.getDate()+expiredays);
30 document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; path=/; expires="+exdate.toGMTString());
31}
21function setCookie (c_name, value, expiredays) {
22 var exdate = new Date();
23 exdate.setDate(exdate.getDate() + expiredays);
24 document.cookie = c_name + '=' + escape(value) + ((expiredays == null) ? '' : ';expires=' + exdate.toGMTString())+ '; path='+window.nps.web_base_url+'/;';
25}
52function setCookie(key, value, expires) {
53 var exp = new Date();
54 exp.setTime(exp.getTime() + expires * 24 * 60 * 60 * 1000);
55 document.cookie = key + '=' + escape(value) + ';expires=' + exp.toUTCString();
56}
223export function setCookie(name, value, expires, sameSite) {
224 let expTime = new Date();
225 expTime.setTime(expTime.getTime() + expires * 1000 * 60);
226 window.document.cookie = name + '=' + encodeURIComponent(value) + ';path=/;expires=' +
227 expTime.toGMTString() +
228 (sameSite ? ';SameSite=' + sameSite : '');
229}
370function setCookie(cookieName, cookieValue, expiredays) {
371 var exdate = new Date();
372 exdate.setDate(exdate.getDate() + expiredays);
373 document.cookie = cookieName + "=" + escape(cookieValue) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
374}
7function setCookie(cookieName, cookieValue, nDays) {
8 var today = new Date();
9 var expire = new Date();
10 if (nDays === null || nDays === 0){ nDays = 1;}
11 expire.setTime(today.getTime() + 3600000 * 24 * nDays);
12 document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString() + ";path=/";
13}

Related snippets