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:-

 

 

 

 

 

Related Posts

  • 49
    This section will provide you with the basics of what JavaScript is, and why you should use it. Objectives     JavaScript versus JAVA     Interpreted programs versus Compiled programs     Why JavaScript     What you can use JavaScript for     About JavaScript JavaScript is a lightweight, interpreted programming language. It…
    Tags: javascript, language
  • 42
    Let us take a sample example to print out "Hello World". We added an optional HTML comment that surrounds our JavaScript code. This is to save our code from a browser that does not support JavaScript. The comment ends with a "//-->". Here "//" signifies a comment in JavaScript, so…
    Tags: javascript
  • 41
    JavaScript Datatype One of the most fundamental characteristics of a programming language is the set of data types it supports. These are the type of values that can be represented and manipulated in a programming language. JavaScript allows you to work with three primitive data types − Numbers, 123, 120.50…
    Tags: javascript
  • 39
    A function is a group of reusable code which can be called anywhere in your program. This eliminates the need of writing the same code again and again. It helps programmers in writing modular codes. Functions allow a programmer to divide a big program into a number of small and…
    Tags: javascript
  • 39
    Tags: javascript

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: