检查用户是否在浏览器会话中访问过网站 [英] Check if user has alread visited site in browser session

查看:123
本文介绍了检查用户是否在浏览器会话中访问过网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个初始屏幕动画,当你访问我的网站。然而,我只想要动画播放第一次你访问它(在会话当然)。我试图做一个if else,我检查一个cookie称为会话,如果存在,删除包含动画的div。如果没有此类Cookie,请创建它。

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) {
        $('.splash').remove(this);
    } else {
        document.cookie = "visited";
    }
}

我从来没有使用过cookies,所以我想我可能发生了一些错误

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

推荐答案

代码中处理cookie的部分应该可以正常工作。

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

您的问题存在于此行上:

Your problem exists on this line:

$('.splash').remove(this);

删除,因为没有必要。

Remove this, as it's not necessary.

该行应如下所示:

$('.splash').remove();

希望有帮助。

这篇关于检查用户是否在浏览器会话中访问过网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆