gpt4 book ai didi

javascript - JQuery Cookie.js 保存 cookie

转载 作者:行者123 更新时间:2023-11-28 04:04:38 26 4
gpt4 key购买 nike

您好,我正在使用 jquery cookie.js 来存储 cookie。

我已经搜索了代码,并且使用 cookie.js 插件它工作正常,但我遇到一个问题,当我刷新页面时,cookie 会自动保存并且弹出窗口不会显示。当任何用户进入该网站时,都会出现一个弹出窗口,用户必须单击“继续”按钮才能进入该网站,

我基本上不允许用户在单击“继续”按钮之前进入该网站。

这是我的 html 代码

<div id="popup-container">
<div class="wrapper">
<div id="popup-window">
<div class="splash-bg">
<h1>Are You Over 18? Click Continue if you are or return to previous
page</h1>
<a type="button" class="close">Continue</a>
</div>
</div>

这是我正在使用的js代码

<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#popup-container a.close').click(function(){
jQuery('#popup-container').fadeOut();
jQuery('#active-popup').fadeOut();
});

var visits = jQuery.cookie('visits') || 0;
visits++;

jQuery.cookie('visits', visits, { expires: 1, path: '/' });

console.debug(jQuery.cookie('visits'));

if ( jQuery.cookie('visits') > 1 ) {
jQuery('#active-popup').hide();
jQuery('#popup-container').hide();
} else {
var pageHeight = jQuery(document).height();
jQuery('<div id="active-popup"></div>').insertBefore('body');
jQuery('#active-popup').css("height", pageHeight);
jQuery('#popup-container').show();
}

if (jQuery.cookie('noShowWelcome')) { jQuery('#popup-
container').hide(); jQuery('#active-popup').hide(); }
});

jQuery(document).mouseup(function(e){
var container = jQuery('#popup-container');

if( !container.is(e.target)&& container.has(e.target).length === 0)
{
container.fadeOut();
jQuery('#active-popup').fadeOut();
}

});
</script>

最佳答案

当您有多次 cookie 访问时,cookie 可能不是 cookie 数组中的第一个 cookie,因此您必须尝试使用​​以下两种方式获取该 cookie

jQuery.cookie('visits')

jQuery.cookie(' visits')

关于javascript - JQuery Cookie.js 保存 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46806779/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com