Cookies in JavaScript

Cookies is a method of storing information locally in browser and sending it to server whenever the pages are requested by the user. When a user requests a page, an HTTP request is sent to the server. The request includes a header that defines several pieces of information, including the page being requested. The server returns a HTTP response that also includes a header. The header contains information about the document being returned. These headers all contains one or more fields of information in a basic format like fieldname : information.
 
Example
 
<html>

<head>

</head>

<body bgcolor=”yellow” text=red>

Type any desired word in the text box it will be kept as cookie for this document.

<form mehtod=”post()”>

<br> Cookie value : <input type = text size=10 onchange=”ck(this.value);”> <br>

<input type=”submit”>

</form>

 

<script type=”text/javascript”>

function ck(ff)

{

document.cookie=ff

}

var cooky =((document.cookie != “”) && (document.cookie != null))

var cname=((cooky)? document.cookie: “Hello”)

document.write(“<br>Cookies : “+document.cookie);

</script>

</body>

</html>