Page 173 - Computer Software Application TP - Volume 1
P. 173
COMPUTER SOFTWARE APPLICATION - CITS
TASK 4 : Deleting cookie
1 Open the text editor
2 Write the following codes
<html>
<head>
<title> Cookies </title>
</head>
<body>
<p id=”para”>javascript cookies</p>
<script>
function deleteCookie(name)
{
// Set the cookie name with an empty value and an expired date in the past.
document.cookie = name + “=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;”;
alert(“Cookie not available”);
}
// Example usage:
deleteCookie(“username “);
</script>
</body>
</html>
3 Save the program as a .html file
4 Open the html file with a web browser and verify the output.
1 Write a JavaScript program that creates a cookie named “username” with the value “John” and an expiration
time of 7 days.
2 Write a JavaScript program that creates a cookie named “visited” with the value “true” when a user first visits
a webpage. Check if the cookie exists when the user revisits the page and display a welcome message
accordingly.
3 Create a JavaScript program that prompts the user to enter their preferred language and creates a cookie
named “language” with the chosen language as its value. Ensure that the cookie expires after 30 days.
158
CITS : IT & ITES - Computer Software Application - Exercise 43