I do not understand the following situation.
On the backend I am using Tomcat. Tomcat automatically sends a cookie with name JSESSIONID
which looks something like that cookie-value = FE3C82283FA06B9BE79EF1CE50AEB32E
.
The max-age property is set to session and this cookie is always sent by the server.
Now, on my website I run the following javascript code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Hello From Cookie-LocalStorage-Demo</h1>
<div id="list_cookies_div">
</div>
<script>
function print_cookies() {
console.log("document.cookie = " + document.cookie);
var cookies = document.cookie.split(';');
console.log("print_cookies: cookies.length = " + cookies.length);
for (var i = 0 ; i < cookies.length; i++) {
var div = document.getElementById("list_cookies_div");
div.innerHTML += "Cookie Value = " + cookies[i] + "<br/>"
console.log(i + ":" + cookies[i]);
}
}
window.onload = print_cookies;
</script>
</body>
</html>
When I run this website the output is "" so bascially nothing. I acutally looks like this here:
On the other hand when I have a look at the Developer Tools of the browser I can see the cookie (see screenshot):
Why is the cookie shown in the developer tools but not accessible from javascript on the page?