【问题标题】:Auto popup based on JavaScript/jQuery cookie基于 JavaScript/jQuery cookie 的自动弹出窗口
【发布时间】:2018-04-26 00:01:03
【问题描述】:

我正在尝试在依赖于 js/jQuery cookie 的网站中添加一个自动弹出消息,这意味着该弹出窗口将每天仅向访问者显示一次(而不是每次重新加载页面时都显示)

cookie 将在 24 小时后过期,一旦过期,自动弹出窗口将再次显示。

非常感谢

【问题讨论】:

  • 有什么问题?记得添加一个minimal reproducible example 你到目前为止所做的努力。
  • 感谢您的评论。我的问题是,我怎样才能挂钩 cookie 和我的弹出窗口(灯箱)。所以它每天只能打开一次。

标签: javascript jquery cookies popup


【解决方案1】:

伪代码:

var currentDate = new Date().toLocaleString();
var alertCookieDate = getCookieDate(); 
var alertWasShown = getCookiePopup(); //set here boolean if popup was shown on true and false if not
if(alertCookieDate < currentDate && !alertWasShown){
   alert("popup here");
   updateCookie(); //code to update time here;
   updateCookiePopup(); //set boolean here
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 2021-12-04
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多