Skip to content

Commit 81abab1

Browse files
committed
Add Cookies.html for cookie management functionality
1 parent 6db7bb3 commit 81abab1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
<script>
9+
// create a cookie
10+
function setCookie(name, value) {
11+
12+
document.cookie = name + "=" + (value || "") + expires + "; path=/";
13+
14+
// Set the cookie to expire in 7 days
15+
16+
}
17+
18+
19+
20+
// read a cookie
21+
function get_cookies(){
22+
document.cookie.split(';').forEach(cookie => {
23+
const [name, value] = cookie.split('=');
24+
// console.log(name.trim() + ": " + value);
25+
document.write(name.trim() + ": " + value + "<br>");
26+
});
27+
}
28+
</script>
29+
30+
31+
</head>
32+
<body>
33+
34+
<button onclick="get_cookies()">Get Cookies</button>
35+
<button onclick="setCookie('username', 'JohnDoe')">Set Cookie</button>
36+
37+
</body>
38+
</html>

0 commit comments

Comments
 (0)