Set the cookies associated with the document in JavaScript

Description

The following code shows how to set the cookies associated with the document.

Example


<!-- w  w  w  . ja v  a2 s  . c om-->

<!DOCTYPE HTML>
<html>
<body>
<script>
var cookieCount = 0;
//read Cookies
document.writeln(document.cookie);


//create Cookie
cookieCount++;
document.cookie = "Cookie_" + cookieCount + "=Value_" + cookieCount;


//read Cookies
document.writeln(document.cookie);

</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Set the cookies associated with the document in JavaScript
Home »
  Javascript Tutorial »
    Document »
      Cookie
Javascript Tutorial Cookie
Add date type value as cookie value in Java...
Read cookie by name in JavaScript
Read cookie value and fill the value to for...
Read value from a input text field and use ...
Set cookie with additional items separated ...
Set the cookies associated with the documen...
Update the cookies associated with the docu...
read the cookies associated with the docume...