检查客户端是否接受 javascript 中的 cookie? [英] Check if the client accepts cookie in javascript?
本文介绍了检查客户端是否接受 javascript 中的 cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以检查客户端是否只接受 javascript 代码的 cookie?
Is there any way to check if the client accepts cookies only with javascript code?
推荐答案
这应该可以解决问题:
function areCookiesEnabled() {
document.cookie = "__verify=1";
var supportsCookies = document.cookie.length >= 1 &&
document.cookie.indexOf("__verify=1") !== -1;
var thePast = new Date(1976, 8, 16);
document.cookie = "__verify=1;expires=" + thePast.toUTCString();
return supportsCookies;
}
这会设置一个基于会话过期的 cookie,检查它是否存在,然后在过去再次设置它,将其删除.
This sets a cookie with session-based expiration, checks for it's existence, and then sets it again in the past, removing it.
这篇关于检查客户端是否接受 javascript 中的 cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文