CSS Chapter 4 (Part 1) Notes by Ur Engineering Friend
CSS Chapter 4 (Part 1) Notes by Ur Engineering Friend
Define Cookies -:
Cookies are small text files stored on a user's device (such as a computer or smartphone) by
websites. These files contain data such as user preferences, session information, or tracking
information. When a user revisits the website, the cookies are read to remember the user's
actions, preferences, and browsing history. This enables the website to provide a more
personalized experience and helps with functions like logging in automatically or keeping
items in a shopping cart.
Types of Cookies:
• Session Cookies:
o These cookies are temporary and are erased when the user closes the web
browser. They store information that is only necessary for a single session, such
as login information or items in a shopping cart.
o Example: A shopping cart cookie that vanishes after you leave the site or close
the browser.
• Persistent Cookies:
o Persistent cookies remain on a user’s device for a predetermined period of time,
even after the browser is closed. These cookies help websites remember user
preferences or actions over multiple sessions.
o Example: Cookies that save login information so that you don’t have to re-enter
your credentials each time you visit the site.
Cookies Operation -:
Creating cookies in JavaScript is simple and can be done using the document.cookie property.
Here's how you can create, read, and delete cookies with a small HTML and JavaScript
example.
Creating Cookie -:
Key Parts:
In JavaScript, you can read cookies using the document.cookie property. The document.cookie
string contains all the cookies for the current page. However, since all cookies are stored in a single
string separated by semicolons, you will need to parse them to get individual cookie values.
Deleting Cookie -:
Cookies in JavaScript are stored in the document.cookie property. Deleting a cookie is done by
setting the cookie's expiration date to a past time.
<html>
<head>
<meta charset="UTF-8">
scale=1.0">
<script>
function createCookie() {
const name =
document.getElementById("nameInput").value;
} else {
cookie.");
function readCookie() {
if (cookie.indexOf(nameEQ) === 0) {
const username =
cookie.substring(nameEQ.length, cookie.length);
function deleteCookie() {
alert("Cookie deleted.");
</script>
</head>
<body>
name">
<br><br>
</body>
</html>