Skip to main content

Posts

Showing posts from May, 2018

Creating Cookies in JavaScript

Creating Cookies in JavaScript   We all use a browser which automatically logs us in to our favorite sites without us having to login manually every time. A cookie is sent from a web site and stored locally on your computer. It is just a piece of data which allows web sites to remember their users. In this post we will learn how to create cookies with JavaScript. How are cookies stored? Cookies are stored in name-value pairs i.e. like this, user = deecoder This value is stored in a text file. Whenever the site related to this is visited, the cookie is added to the web request. Hence web-server doesn’t have to remember about you. How to create Cookies in JavaScript? Cookies can be created by assigning a name-value pair to the document.cookie object. This can be done like this.., document.cookie="username=Yourname; expires=Wed, 19 Nov 2018 12:00:00 UTC; path=/";     // username, expires, path are called parameters. Here we have created a cookie for a