I have a home page with a choice of 2 links. When one of those links is clicked I want to create a cookie so that all other internal pages remember this choice.
How do I set a cookie on one page and read the same cookie on different pages?
This is what I have:
// Home page on click event
function setRed() {
document.cookie = "color=red; max-age=" + 60 * 60 * 24 * 365; // 60 seconds to a minute, 60 minutes to an hour, 24 hours to a day, and 365 days.
};
//Internal Page Check
window.onload = checkCookie();
function checkCookie() {
if (document.cookie.indexOf("color") == "red") {
document.body.id = "red";
} else {
document.body.id = "blue";
};
};