Primarily for the sake of learning and testing I want to set the simplest cookie ever, containing only one letter and then get it.
In page A I run in console:
set cookie myCookie = "a"
In page B I run in console:
I assume that “get” here may be a
console.log(myCookie) or a
I am not sure I understand how is it done. For example:
document.cookie = "username=John Doe";
I don’t find any naming being done.
I mean, if we set a variable we give it a name such as in:
const bestNameEverInHistory = "a"`
Then we can
How could we
console.log() a cookie if there is no naming?
So it’s like an HTML command with attribute/s and value/s output.
Okay. The syntax there is a bit confusing to me.
What I don’t get is why there is a formal way to display one or more cookie/s output:
allCookies = document.cookie;
I even got different colors in console:
I thought that there are two or more cookie strings.
I guess than, that cookies is not what I need for this task, rather, local storage is what I need for it.
depends on what you’re trying to store in the cookie.
The thing you pasted a screenshot of above is… at least 6 cookies. one called _gc1_au, one called __qca, one called _hjSessionUser_1088957, one called _gid, one called _ga_QPSK9L63NG, and one called _ga.
Cookies are for sending information to the server (or more specifically, storing information the server sends to you, so you can send it back if needed). If you’re trying to store information locally that originates from the user, localStorage would be the better option.
I do wonder, why are the names of the cookies above so “technical”?
Shouldn’t there be more “human readable” names?
Why? They’re not for humans to read.
When’s the last time you read your cookies? Have you read your cookies from this site?
Today was the first and so far last.
But I have read maybe 10,000 dramatic “cookie statements” in various websites in the last 5 years or so…
That made me think, that if people store cookies in the user’s browser, they should make them clear if that user wants to read their content… Maybe as a legal requirement…
var thisIsAThingToDoSomeStuff = 4
or i can say
var x = 4
If you never read it, what’s the difference? Your browser doesnt care what it’s called, it just knows there is a thing, and it has a value of 4.
Most of the cookies in your string, for the record, are parts of Google Analytics tracking cookies that basically every major site in the world uses. Do you care? Does it make it any different now that you know what they’re for?
That’s a good question
I think most of the time I don’t care. But I can’t say that I’ll never care
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.