【问题标题】:Want to display my survey window once in 30 days to each user想在 30 天内向每个用户显示一次我的调查窗口
【发布时间】:2017-01-11 18:04:28
【问题描述】:

我有代码可以在单击提交按钮时显示调查弹出窗口,现在我想每 30 天向每个用户显示一次调查。你能帮我编写代码,每 30 天显示一次吗,这是我现有的代码。

        if(document.getElementById("submit")){
            if(jQuery("[name='systemCompanyName']").val() == 'xxxx'){
                document.getElementById("submit").onclick =     function(){
                     var answer = confirm("Please click on OK to take a short survey")
                if(answer)
                window.open(url);

            };
        };
    };

【问题讨论】:

  • 听起来像是你可以使用cookies 的东西。如果您设置了一个过期 30 天的 cookie,然后将程序设置为自动检查 cookie 是否存在,如果不存在则启动调查

标签: javascript jquery popup popupwindow


【解决方案1】:

如果调查完成,请致电第一个确定日期。第二个检查是否经过了第 n 天。

function surveyCalled(){

        var data = JSON.stringify({"date":new Date()}) || null;
        localStorage.setItem("survey",data);

}

function checkSurvey(days){

        var data = JSON.parse(localStorage.getItem("survey")) || {};

            if(data.date){

                if(Math.round((new Date() - new Date(data.date)) / (1000 * 60 * 60 * 24)) >= days){

                    return true;

                }

          }

      return false;

}


console.log(checkSurvey(10))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-27
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多