Blu Blu - 1 year ago 57
Javascript Question

Check if user has alread visited site in browser session

So I have this splash screen animation that plays when you visit my website. However, I only want the animation to play the first time you visit it (in the session of course). I tried to make an if else where I check for a cookie called "Session", and if it exists, delete the div containing the animation. If there is no such cookie, create it.


function session() {
if (document.cookie.indexOf("visited") >= 0) {
} else {
document.cookie = "visited";

I have never used cookies before so I think I might have made some errors

Answer Source

The portion of your code that deals with cookies should work.

Your problem exists on this line:


Remove this, as it's not necessary.

That line should look like:


Hope that helps.