Js 判断浏览器cookie 是否启用
验证时 google浏览器 135.0.7049.117 不生效
- cookie.html
<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><title>Cookie 检测</title>
</head>
<body><h1>检测是否启用 Cookie</h1><p>页面加载后会自动检测。</p><script>function checkCookiesEnabled() {// Try setting a temporary cookiedocument.cookie = "testCookie=testValue; max-age=5; path=/";// Check if the cookie was setif (document.cookie.indexOf("testCookie=") !== -1) {// Cookie is enabled, now clear the temporary cookiedocument.cookie = "testCookie=; max-age=0; path=/";return true;} else {return false;}}if (checkCookiesEnabled()) {console.log("Cookies are enabled (verified by setting a cookie).");} else {console.log("Cookies are disabled (verified by setting a cookie).");}</script>
</body>
</html>
- cookie.html 同级文件夹 启动服务
python -m http.server 8000
- 访问服务
http://localhost:8000/cookie.html