Get cookie by name
Sun Oct 06 2024 03:18:57 GMT+0000 (Coordinated Universal Time)
Saved by
@kanatov
function getCookie(name) {
const cookieArr = document.cookie.split(";");
for (let cookie of cookieArr) {
cookie = cookie.trim();
if (cookie.startsWith(name + "=")) {
return cookie.substring(name.length + 1);
}
}
return null;
}
const myCookie = getCookie("cookieName");
content_copyCOPY
Comments