8 views
Can you set a cookie yourself in the browser, without a server?
Asked at
AI answer
Yes. JavaScript can set a cookie in the browser through document.cookie, for example:
document.cookie = "theme=dark; Max-Age=3600; Path=/; SameSite=Lax; Secure";
This works for a cookie belonging to the current site, subject to browser restrictions. JavaScript cannot set a cookie with the HttpOnly flag—only the server can create such a cookie, and it is not accessible through document.cookie. The Secure flag requires HTTPS. Browsers also restrict setting cookies for other domains and may block third-party cookies.
Also asked at СБЕР
- Have you worked with useLayoutEffect and how does it differ from useEffect?
- [name] asked: why did you decide to change your job?
- What is Event Loop in JavaScript?
- What is Virtual DOM and how does it work in React?
- Please tell us about your experience: what tasks do you solve, what is your area of responsibility, what technologies have you worked with, and how are the team processes organized?