0% found this document useful (0 votes)
147 views

Write A Program To Create A Session Cookie and Display Content of Cookie

The document contains code for two JavaScript programs. The first program creates a session cookie that stores a username and displays the cookie. The second program creates a persistent cookie that stores a username with an expiration date one month later, and alerts the user of the expiration date.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Write A Program To Create A Session Cookie and Display Content of Cookie

The document contains code for two JavaScript programs. The first program creates a session cookie that stores a username and displays the cookie. The second program creates a persistent cookie that stores a username with an expiration date one month later, and alerts the user of the expiration date.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Practica 9

/* 1. Write a program to create a session cookie and display


content of Cookie */

<html>
<script lang="Javascript" type="text/javascript">
function Cookie()
{ var cookie_val = name.value;
document.cookie = "<b>Username = </b>"+ cookie_val;
alert("Cookie created");
}
</script>
<body>
Enter your Name : <input type="text" id="name"/><br>
<input type="button" value="Create Cookie"
onclick="Cookie()"/>
</body>
</html>
Practica 9

/* 2. Write a JavaScript that creates persistent cookie */

<html>
<script>
function persistent_cookie()
{ var now = new Date();
now.setMonth(now.getMonth()+ 1);
var cookie_val = user.value;
document.cookie = "Username = "+cookie_val
+"Expires = "+ now.toUTCString();
alert("Expiry Date of Cookie : "+
now.toUTCString());
}
</script>

<body>
Enter Name : <input type="text" id="user"/> <br>
<input type="button" value="Cookie"
onclick="persistent_cookie()"/>
</body>
</html>

You might also like