Answer the question
In order to leave comments, you need to log in
If you save a cookie in the browser using JS, will the cookie be passed to the server?
There is a JavaScript variable that is responsible for the height of the block on the page, I want to save this variable and set the desired height when the page is reloaded. Cookies are stored using this code:
function setCookie(name, value, options={}) {
var expires = options.expires;
if (typeof expires == "number" && expires) {
var d = new Date();
d.setTime(d.getTime() + expires * 1000);
expires = options.expires = d;
}
if (expires && expires.toUTCString) {
options.expires = expires.toUTCString();
}
value = encodeURIComponent(value);
var updatedCookie = name + "=" + value;
for (var propName in options) {
updatedCookie += "; " + propName;
var propValue = options[propName];
if (propValue !== true) {
updatedCookie += "=" + propValue;
}
}
document.cookie = updatedCookie;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question