在不检查大量单个 cookie 的情况下,我如何检测网站是否设置了一般 cookie。
我看了这个类似的问题:Create a cookie if (and only if) it doesn't already exist。但是那里提供的解决方案会检查是否存在特定的 cookie,而不仅仅是一般的 cookie。
我试过了:
if($.cookie) {
//code
}
在不检查大量单个 cookie 的情况下,我如何检测网站是否设置了一般 cookie。
我看了这个类似的问题:Create a cookie if (and only if) it doesn't already exist。但是那里提供的解决方案会检查是否存在特定的 cookie,而不仅仅是一般的 cookie。
我试过了:
if($.cookie) {
//code
}
jQuery 真的不需要检查当前域是否在用户的浏览器中设置了 cookie,只需使用原始 JS:
if(document.cookie.length > 0) {
// do stuff ...
}
检查cookie是否存在:
if (document.cookie === "") {
// do something if no cookie exists
}
我不会为此使用 jquery 来保护内存/处理
您不需要为此使用 $.cookie 插件:
if (document.cookie) {
// at least one cookie has been set...
}