我在使用 js-cookie 设置两个 cookie 时遇到了一些麻烦。我有一个引导模式,在页面加载时出现 15 秒。模态中是一个电子邮件订阅表格。单击订阅按钮后,它会创建一个 cookie,以防止未来弹出。如果此人决定不订阅,我想创建第二个 cookie。他们可以单击 x 关闭。我希望 x 创建另一个 cookie 以防止弹出但仅在 1 天内过期。它似乎在 Chrome 中工作,但是当我在 Firefox 上仔细检查时,它不起作用。
这是我之前的JS
<script src='https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.2/js.cookie.js'/>
<script>
//<![CDATA[
$(document).ready(function(){
if(!Cookies.get('hide-div'))
if(!Cookies.get ('popup')){
setTimeout(function() {
$('#myModal').modal();
}, 15000);
}
$("#sub-button").click(function () {
Cookies.set('hide-div', true, { expires: 1000 });
});
$("#sub-button2").click(function () {
Cookies.set('hide-div', true, { expires: 1000 });
});
$("#preventpopup").click(function () {
Cookies.set('popup', true, { expires: 1 });
});
})
//]]>
</script>
HTML
<!-- Modal -->
<div aria-labelledby='myModalLabel' class='modal fade' id='myModal' role='dialog' tabindex='-1'>
<div class='modal-dialog' role='document'>
<div class='modal-content' style='background-color: rgb(255, 241, 237);'>
<div class='modal-body'>
<button aria-label='Close' class='close' data-dismiss='modal' type='button'>
<span aria-hidden='true' id='preventpopup'>×</span>
</button>
<h4 class='modal-title' id='myModalLabel' style='text-align: center;font-size: 60px; font-family: 'Allura', cursive;margin-top: 25px;'>Let's be mom friends!</h4>
<h6 style='text-align: center; text-transform: uppercase; font-family: raleway;'>Subscribe today to receive exclusive MIM content updates directly to your inbox!</h6>
<form action='https://feedburner.google.com/fb/a/mailverify' data-toggle='validator' id='myform' method='post' onsubmit='window.open('https://feedburner.google.com/fb/a/mailverify?uri=blogspot/CqrSa', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true' style='padding:3px;text-align:center;' target='popupwindow'>
<p style='font-family: raleway; text-transform: uppercase; margin-top: 20px;'>Enter your email address:</p>
<p>
<input class='form-control' data-error='Please enter a valid email.' id='inputEmail' name='email' style='width:250px; display:inline-block' type='email'/>
<div class='help-block with-errors'/>
</p>
<input name='uri' type='hidden' value='blogspot/CqrSa'/> <input name='loc' type='hidden' value='en_US'/>
<div class='form-group'>
<input class='btn btn-primary' id='sub-button' style='font-family: raleway; text-transform: uppercase; margin-bottom: 25px;' type='submit' value='Subscribe'/>
</div>
<h6 aria-label='Close' data-dismiss='modal' id='sub-button2' type='button'><a href='#'>Already a subscriber? Click here to prevent future pop ups.</a></h6>
<h6><small>This website uses cookies so that we may provide you with the best user experience.</small></h6>
</form>
</div>
</div>
</div>