Javascript with Cookies

Cookie is simply a variable that your webpage can store on or retrieve from the user’s computer to host machine.

Examples of cookies could be:
First time the visitor arrives the name is entered.(for example “John Wayne”). The username is then stored in a cookie. Next time he arrives at your page, it writes something like: “Welcome to my page John Wayne!!
Good to see you again”. The name is simply retrieved from the stored cookie.

First time the user arrives at your page she enters the desired language.
The chosen language is stored in a cookie.
Next time she visits your site, she will simply be taken to the pages in the desired language without asking, since the desired language is retrieved from the cookie.

First time the user arrives at your page he is asked to fill in a password.The password is saved in a cookie. Next time he arrives at your page, the password is retrieved from the cookie.

Veritable length in cookies :-

Expires − The date the cookie will expire. If this is blank, the cookie will expire when the visitor quits the browser.

Domain :- The domain name of your site.

Path :-The path to the directory or web page that set the cookie. This may be blank if you want to retrieve the cookie from any directory or page.

Secure :-If this field contains the word “secure”, then the cookie may only be retrieved with a secure server. If this field is blank, no such restriction exists.

Name=Value :- Cookies are set and retrieved in the form of key-value pairs

How to create cookies in javascript:-

 

 

 

 

 

Leave a Reply