Quantcast

Creating and Storing Cookies with JAVA Script

A cookie is a variable that is stored on the visitor’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With JavaScript, you can both create and retrieve cookie values. Two examples of cookies are cookie name and cookie password. The first time a visitor arrives to your web page, he or she must fill in her/his name. The name is then stored in a cookie. Next time the visitor arrives at your page, he or she could get a welcome message like “Welcome to My Computer!” The name is retrieved from the stored cookie. Similarly, the first time a visitor arrives to your web page, he or she must fill in a password. The password is then stored in a cookie. Next time the visitor arrives at your page, the password is retrieved from the cookie.

Now, consider an example which creates and stores a cookie containing the name of the visitor. Take a look at this code:

The parameters of the function above hold the name of the cookie, the value of the cookie, and the number of days until the cookie expires.

Now a function that would return a specified cookie:

The function above makes an array to retrieve cookie names and values, then it checks if the specified cookie exists, and returns the cookie value. JAVA script is the most powerful yet a very simple tool to deal with the process of creation and storing of the cookies and hence is a very handy tool for any web developer.

Looking for a quality hosting service? here are a few I suggest.
BlueHost | HostGator | Media Temple
Admin
Admin
Ali has been an entrepreneur in web, video and related technologies. Having worked with many business across the globe, Ali stands truly a great pillar in the business working with him.