Jquery 设置cookie弹出窗口

Jquery 设置cookie弹出窗口,jquery,html,css,cookies,Jquery,Html,Css,Cookies,我正在尝试做每个页面现在都有的典型弹出窗口。 “此网站使用Cookie。继续浏览此网站即表示您同意我们使用Cookie。” 我创建了这段代码,通过单击关闭按钮使弹出窗口消失,但每次我加载页面时,弹出窗口仍然可见 我还想知道这些弹出窗口的正常cookie过期时间是多少 你能帮我吗 HTML5 JS 我正在使用JQuery Cookies插件 我认为当刷新页面时,您的弹出窗口是可见的,因为您在上检查cookie。cookies\u close单击。我会这样做: $(document).ready(f

我正在尝试做每个页面现在都有的典型弹出窗口。 “此网站使用Cookie。继续浏览此网站即表示您同意我们使用Cookie。”

我创建了这段代码,通过单击关闭按钮使弹出窗口消失,但每次我加载页面时,弹出窗口仍然可见

我还想知道这些弹出窗口的正常cookie过期时间是多少

你能帮我吗

HTML5

JS


我正在使用JQuery Cookies插件

我认为当刷新页面时,您的弹出窗口是可见的,因为您在
上检查cookie。cookies\u close
单击。我会这样做:

$(document).ready(function(){

if($.cookie('Terms')){
    $('#cookies_alert').addClass("closed");
}

$('.cookies_close').on('click', function () {
    $.cookie('Terms', 'Terms', { expires: 7 });
    $('#cookies_alert').addClass("closed");
});
});
if (window.localStorage) {
  // Check if the user is already accepted the cookie policy
  if (!localStorage.getItem("userAgreed")) {
    $("#cookies_alert").show();
  } else {
    $("#cookies_alert").hide();
  }
}


// On click agree
$("#cookies_alert button").on("click", function(event) {
  event.preventDefault();
  localStorage.setItem("userAgreed", true);
  $("#cookies_alert").hide();
});

// On click of close button
$("#cookies_alert a.close").on("click", function(event) {
  event.preventDefault();
  $("#cookies_alert").hide();
});

就个人而言,要使此cookie策略过期,我将使用以下内容:

$(document).ready(function(){

if($.cookie('Terms')){
    $('#cookies_alert').addClass("closed");
}

$('.cookies_close').on('click', function () {
    $.cookie('Terms', 'Terms', { expires: 7 });
    $('#cookies_alert').addClass("closed");
});
});
if (window.localStorage) {
  // Check if the user is already accepted the cookie policy
  if (!localStorage.getItem("userAgreed")) {
    $("#cookies_alert").show();
  } else {
    $("#cookies_alert").hide();
  }
}


// On click agree
$("#cookies_alert button").on("click", function(event) {
  event.preventDefault();
  localStorage.setItem("userAgreed", true);
  $("#cookies_alert").hide();
});

// On click of close button
$("#cookies_alert a.close").on("click", function(event) {
  event.preventDefault();
  $("#cookies_alert").hide();
});

我相信大多数网站的默认cookie过期时间都是一个月。

我这里遗漏了一些东西。代码中的过期时间设置在哪里?这是在使用本地存储,而不是cookies,我认为在这里没有过期时间。如果我错了,请纠正我。
if (window.localStorage) {
  // Check if the user is already accepted the cookie policy
  if (!localStorage.getItem("userAgreed")) {
    $("#cookies_alert").show();
  } else {
    $("#cookies_alert").hide();
  }
}


// On click agree
$("#cookies_alert button").on("click", function(event) {
  event.preventDefault();
  localStorage.setItem("userAgreed", true);
  $("#cookies_alert").hide();
});

// On click of close button
$("#cookies_alert a.close").on("click", function(event) {
  event.preventDefault();
  $("#cookies_alert").hide();
});