| Refresh | Home EGTry.com

document.cookie, create and update a cookie


step 1. show the cookie

alert(document.cookie); //no content


step 2. create a new session cookie

document.cookie="cookie1=the first cookie";
alert(document.cookie); //cookie1=the first cookie


step 3. create another session cookie

document.cookie="cookie2=another cookie";
alert(document.cookie); //cookie1=the first cookie; cookie2=another cookie"


step 4. update the first cookie value

document.cookie="cookie1=the first cookie updated";
alert(document.cookie); //cookie1=the first cookie updated; cookie2=another cookie"


step 5. close the browser and reopen the same page. all session cookie are gone

alert(document.cookie); //nothing