1 //Create a cookie2 functionSetcookie (name, value, expires, path, domain, secure) {3 varCookietext = encodeURIComponent (name) + ' = ' +encodeURIComponent (value);4 if(ExpiresinstanceofDate) {5Cookietext + = '; Expires= ' +expires; 6 }7 if(path) {8Cookietext + = '; Expires= ' +expires; 9 }Ten if(domain) { OneCookietext + = '; Domain= ' +domain; A } - if(secure) { -Cookietext + = '; Secure; the } -Document.cookie =Cookietext; - } - //Get Cookies + functionGetCookie (name) { - varCookieName = encodeURIComponent (name) + ' = '; + varCookiestart =document.cookie.indexOf (cookiename); A varCookievalue =NULL; at if(Cookiestart >-1) { - varCookieend = Document.cookie.indexOf ('; '), Cookiestart); - if(Cookieend = =-1) { -Cookieend =document.cookie.length; - } -Cookievalue = decodeURIComponent (document.cookie.substring (Cookiestart +cookiename.length, Cookieend)); in } - returnCookievalue; to } + //Delete Cookies - functionUnsetcookie (name) { theDocument.cookie = name + "=; Expires= "+NewDate (0); *}
Get and set Cookie--javascript code implementation