1function deleteAllCookies() {
2 var cookies = document.cookie.split(";");
3
4 for (var i = 0; i < cookies.length; i++) {
5 var cookie = cookies[i];
6 var eqPos = cookie.indexOf("=");
7 var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
8 document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
9 }
10}
11
12deleteAllCookies();
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"
1//set the vvalue to EMPTY, and the date to an already PASSED one.
2document.cookie = "cookiename= ; expires = Thu, 01 Jan 1970 00:00:00 GMT"
1document.cookie = 'my_cookie=; path=/; domain=.example.com; expires=' + new Date(0).toUTCString();
1
2document.cookie = "username=; expires=Thu, 01
3Jan 1970 00:00:00 UTC; path=/;";
4