Cannot read cookies written from javascript

Asked 1 years ago, Updated 1 years ago, 395 views

The javascript cannot read cookies written using document.cookie.
The session can be read by console.log(document.cookie), but when I restart the browser(firefox), the result of console.log(document.cookie) becomes empty string.
You have configured max-age and the developer tool confirms that cookies are stored.

Even though the cookie is saved, if the session is switched, the document.cookie will not be able to read it.
I would appreciate it if you could provide me with a solution.

function cookieWrite() {
document.cookie="cookie=test;max-age=2592000";
}
function cookieRead() {
console.log ( document.cookie);
}

javascript html firefox cookie

2023-01-03 12:14

1 Answers

"Session switching" means closing the browser once and launching the same page again.

You didn't specify the expires attribute, did you?In this case, the cookies are stored only in browser memory.Therefore, the cookies disappear when you close the browser.

Why don't you use a capture tool such as Fiddler to capture requests and responses and see if the header contains cookies?


2023-01-03 20:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.