因此,当您访问我的网站时,我会播放这个启动画面动画。 但是,我只希望动画在你第一次访问时播放(当然在会话中)。 我尝试在if中检查名为“Session”的cookie,如果它存在,则删除包含动画的div。 如果没有这样的cookie,请创建它。
码:
function session() { if (document.cookie.indexOf("visited") >= 0) { $('.splash').remove(this); } else { document.cookie = "visited"; } }我之前从未使用过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.
Code:
function session() { if (document.cookie.indexOf("visited") >= 0) { $('.splash').remove(this); } else { document.cookie = "visited"; } }I have never used cookies before so I think I might have made some errors
最满意答案
代码中处理cookie的部分应该有效。
您的问题存在于此行:
$('.splash').remove(this);删除this ,因为没有必要。
该行应如下所示:
$('.splash').remove();希望有所帮助。
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.
That line should look like:
$('.splash').remove();Hope that helps.
检查用户是否在浏览器会话中访问了访问过的站点(Check if user has alread visited site in browser session)因此,当您访问我的网站时,我会播放这个启动画面动画。 但是,我只希望动画在你第一次访问时播放(当然在会话中)。 我尝试在if中检查名为“Session”的cookie,如果它存在,则删除包含动画的div。 如果没有这样的cookie,请创建它。
码:
function session() { if (document.cookie.indexOf("visited") >= 0) { $('.splash').remove(this); } else { document.cookie = "visited"; } }我之前从未使用过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.
Code:
function session() { if (document.cookie.indexOf("visited") >= 0) { $('.splash').remove(this); } else { document.cookie = "visited"; } }I have never used cookies before so I think I might have made some errors
最满意答案
代码中处理cookie的部分应该有效。
您的问题存在于此行:
$('.splash').remove(this);删除this ,因为没有必要。
该行应如下所示:
$('.splash').remove();希望有所帮助。
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.
That line should look like:
$('.splash').remove();Hope that helps.
发布评论