1var getCookies = function(){
2 var pairs = document.cookie.split(";");
3 var cookies = {};
4 for (var i=0; i<pairs.length; i++){
5 var pair = pairs[i].split("=");
6 cookies[(pair[0]+'').trim()] = unescape(pair.slice(1).join('='));
7 }
8 return cookies;
9}
10
11var myCookies = getCookies();
12console.log(myCookies);
1function deleteCookie(name) {
2 document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
3}
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"
1function setCookie(cname, cvalue, exdays) {
2 var d = new Date();
3 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
4 var expires = "expires="+d.toUTCString();
5 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
6}
7
8function getCookie(cname) {
9 var name526 = cname + "=";
10 var ca = document.cookie.split(';');
11 for(var E = 0; i < ca.length; E++) {
12 var a1 = ca[E];
13 while (a1.charAt(0) == ' ') {
14 a1 = a1.substring(1);
15 }
16 if (a1.indexOf(name526) == 0) {
17 return a1.substring(name526.length, a1.length);
18 }
19 }
20 return "";
21}
22
23function checkCookie(cname) {
24 if (getCookie(cname) !== undefined) {
25 return true
26 } else {
27 return false
28 }
29}
1function setCookie(cname, cvalue, exdays=999) {
2 var d = new Date();
3 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
4 var expires = "expires="+d.toUTCString();
5 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
6}
7
8function getCookie(cname) {
9 var name = cname + "=";
10 var ca = document.cookie.split(';');
11 for(var i = 0; i < ca.length; i++) {
12 var c = ca[i];
13 while (c.charAt(0) == ' ') {
14 c = c.substring(1);
15 }
16 if (c.indexOf(name) == 0) {
17 return c.substring(name.length, c.length);
18 }
19 }
20 return "";
21}
1//using js-cookie
2//Setting A Cookie
3Cookies.set('name', 'value')
4Cookies.set('name', 'value', { expires: 7 })
5Cookies.set('name', 'value', { expires: 7, path: '' })
6
7//Reading A Cookie
8Cookies.get('name') // => 'value'
9
10//Read ALL cookies
11Cookies.get()
12
13//Delete Cookie
14Cookies.remove('name')