检查用户是否在浏览器会话中访问过网站
所以我有这个初始屏幕动画,当你访问我的网站。然而,我只想要动画播放第一次你访问它(在会话当然)。我试图做一个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();
希望有帮助。