The best solution for this IMO is local storage. Cookie files can be useful with browsers - but they can be cleared by the user or automatically (after closing a private window).
How to set the cookie (including the expiry date):
document.cookie = "value; expires=Thu, 01 Jan 2025 00:00:00 UTC; path=/;";
How to read cookie:
const cookie = getCookie("value");
if (cookie === "value2") {
console.log("I get value 2");
} else {
console.log("I get other value");
}
How to set the local storage:
localStorage.setItem('name', 'value');
How to read the local storage:
const storage = localStorage.getItem('name');
if (storage === 'value2') {
console.log("I get value 2");
} else {
console.log("I get other value");
}
If you want more information, write a comment. Remember if my answer was helpful - mark it as helpful