-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookie_write_test.html
94 lines (82 loc) · 2.31 KB
/
cookie_write_test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function load() {
const urlParams = new URLSearchParams(window.location.search);
var count = parseInt(urlParams.get('count'));
if (!count || count <= 0) {
count = 10;
}
console.log("Count: " + count);
var name = urlParams.get('name');
if (!name) {
name = "awesomeCookie";
}
var other = urlParams.get('other');
var i = 0;
var inter = setInterval(function() {
if (i >= count) {
console.log("DONE! exit");
clearInterval(inter);
setTimeout(function() {
var j = 0;
for (let j = 0; j < count; ++j) {
var tmp_name = "XYZ" + name + j + "XYZ";
if (getCookie(tmp_name).length == 0) {
document.getElementById("set_cookie").innerHTML += " " + tmp_name
}
}
if (other) {
for (let j = 0; j < count; ++j) {
var tmp_name = "XYZ" + other + j + "XYZ";
if (getCookie(tmp_name).length == 0) {
document.getElementById("set_cookie").innerHTML += " " + tmp_name
}
}
}
document.body.style.backgroundColor = "blue";
}, 10000);
return;
}
var cookieName = "XYZ" + name + i + "XYZ";
var value = "XYZvalue" + i + "XYZ";
setCookie(cookieName, value, 5);
console.log("Cookie set " + cookieName + "=" + value);
++i;
document.getElementById("all_cookies").innerHTML = "All cookies: " + document.cookie;
}, 1);
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
</script>
</head>
<body onload="load()" bgcolor="yellow">
<div width="100%" height="100%">
Missing:
</div>
<div width="100%" height="100%" id="set_cookie"></div>
<div width="100%" height="100%" id="all_cookies" style="font-size:small">
No cookies
</div>
</body>
</html>