【发布时间】:2016-04-28 08:33:54
【问题描述】:
在我当前的项目中,每次他/她登录网站时,我都必须显示一个弹出窗口(欢迎信息)。在弹出窗口中,用户可以选择(Onclick CheckBox)隐藏弹出窗口 30 天。
当他/她单击弹出窗口上的复选框时,我通过将 UserUniqueId 保存到 cookie(应该是数组/列表)来实现这一点。如下
var UniqueId = "xxx";
var uIDCookies = [];
// looping to get all the values that are stored in cookie
$.each($.cookie(), function(i, v) {
uIDCookies.push(i);
});
// if current userUID not found in cookie then showing popup
if (($.inArray(UniqueId, uIDCookies)) === -1) {
//show popup
} else {
// hide popup
}
// create cookie and set expire time
$('.checkBox').on('click', function () {
var date = new Date();
var minutes = 3;
date.setTime(date.getTime() + (minutes * 60 * 1000));
$.cookie(UniqueId, { expires: date, path: '/' });
//hide popup
});
无论我循环访问存储在客户端浏览器上的所有 cookie 值,我都觉得可能有更好的方法来实现这一点。建议请..!!
【问题讨论】:
-
$.cookie(UniqueId)? -
除非两个用户在同一台计算机上使用同一个浏览器登录网站,否则 cookie 中的用户永远不会超过一个。这是您需要处理的情况吗?其次,将用户 ID 保存在未加密的 cookie 中是一个非常糟糕的主意。
-
Cookie 本地存储在用户的计算机上。我不明白为什么你只有一个用户时应该有多个 uuid。
标签: c# jquery asp.net asp.net-mvc cookies