All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Javascript Cookies

Cookies are used to store information on user device like computer, mobile phones etc. You can store create cookies, access cookies and delete cookies.


You can set as many Cookies as you want.You can also set cookies with the help of PHP.

Create Cookies


Syntax


document.cookie = " key1=value1; key2=value2; key3=value3; expires=date/time ";

Example of Creating Cookies


document.cookie = " name=Rahul; course=BCA;expires=Sun,18 Jan 2015 12:00:00 UTC ";



Read Cookies

var allcookies = document.cookie; document.write(allcookies);

document.cookie statement will give all the cookies into allcookies variable.


Then It display all the cookies like this name=Rahul; course=BCA;




Delete Cookies

You can delete the cookie by setting that keyname and set the expires value to the passed date.


document.cookie = " name=Rahul; course=BCA;expires=Sun,18 Jan 1915 12:00:00 UTC ";

This will delete the name cookie and course cookie.

❮ PreviousNext ❯