There's a good article on working with cookies in Javascript at Mozilla Developer Network: https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
What should help you is Example #3bis:
if (document.cookie.replace(/(?:(?:^|.*;\s*)someCookieName\s*\=\s*([^;]*).*$)|^.*$/, "$1") !== "true") {
alert("Do something here!");
document.cookie = "someCookieName=true; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
}
When you get the value of document.cookie
, you get the semicolon-separated list of cookies. The regular expression in the first line finds the value of cookie named someCookieName
.
When you set the value of document.cookie
, you set or update one cookie (you don't overwrite the whole list of cookies as it may look)
In order to redirect a visitor, you can use document.location
property.
The following code should do what you need:
if (document.cookie.replace(/(?:(?:^|.*;\s*)seenSplash\s*\=\s*([^;]*).*$)|^.*$/, "$1") !== "true") {
document.cookie = "seenSplash=true; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
document.location = "/splash.html";
}