Skip to content

Commit f5cfd43

Browse files
committed
Add a html page for cookie that changes background color
1 parent 5616096 commit f5cfd43

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Diff for: common/src/web/cookie-background.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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>Cookie Demo</title>
7+
<script>
8+
function setTheme(theme) {
9+
document.cookie = "theme=" + theme + "; path=/; SameSite=None; Secure"
10+
applyTheme()
11+
}
12+
13+
function getCookie(name) {
14+
let match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'))
15+
return match ? match[2] : null
16+
}
17+
18+
function applyTheme() {
19+
let theme = getCookie("theme")
20+
document.body.style.backgroundColor = theme || "white"
21+
}
22+
23+
window.onload = applyTheme
24+
</script>
25+
</head>
26+
<body>
27+
<h1>Cookie-Based Demo</h1>
28+
<button id="blue-btn" onclick="setTheme('lightblue')">Light Blue</button>
29+
<button id="green-btn" onclick="setTheme('lightgreen')">Light Green</button>
30+
<button id="reset-btn" onclick="setTheme('white')">Reset</button>
31+
<p>Open this page in multiple tabs/windows to see the shared cookie behavior.</p>
32+
<p>If you open it in a separate user context, the theme will reset.</p>
33+
</body>
34+
</html>

0 commit comments

Comments
 (0)