基础 6 显示打开页面加载,cookie 不起作用

Foundation 6 reveal open on page load with cookies not working

本文关键字:加载 cookie 不起作用 显示 基础      更新时间:2023-09-26

我正在尝试创建一个模态显示,该模式显示使用 zurb 基础 6 在页面加载时打开。我还希望浏览器存储一个cookie,以便如果用户关闭显示,它不会再打扰他们7天。

我正在使用一个jquery插件来获取此处找到的cookie

这是我的网页:

<div class="reveal" id="exampleModal1" data-reveal>
  <h1>Awesome. I Have It.</h1>
  <p class="lead">Your couch. It is mine.</p>
  <p>I'm a cool paragraph that lives inside of an even cooler modal. Wins!</p>
  <button class="close-button" data-close aria-label="Close modal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

如您所见,我没有数据打开元素,因为我希望在页面加载后打开模态。

这是我的jquery:

jQuery(document).ready(function($) {
 if ($.cookie('modal_shown') === null) {
        $.cookie('modal_shown', 'yes', { expires: 7, path: '/' });
        $("#exampleModal1").foundation('reveal', 'open');
    }
});

jquery 处于无冲突模式。

然而,这似乎不起作用。我在 chrome 中通过开发人员控制台没有收到任何错误。我真的很感激你的帮助。

我已经发布了解决方案,以防其他人需要它。

原来,在基础6中,你不需要同时使用揭示和打开的方法,只需打开即可。

jQuery(document).ready(function($) {
  if($.cookie('showed_modal') != "true") {
    $("#exampleModal1").foundation("open");
    $.cookie('showed_modal', 'true', { expires: 7, path: '/'}); 
  }
});