我目前正在为几个网站编码自定义cookie法律解决方案。我试图使解决方案/插件尽可能多的“所有在一个解决方案”与代码被包括在脚本的第一位。目前我已经做了几乎所有的事情,这一切看起来都很漂亮,我想给用户“接受”或“拒绝”的能力,拒绝不仅仅是重定向他们离开,但仍然允许他们使用网站。
到目前为止,我已经正确地为accept和deny设置了一个cookie,它根据选择accept或deny在cookie中设置一个true或false值。
我想使用我找到的代码在if语句中重新定义cookie setter和getter,以防止在用户未给予权限或尚未选择答案时设置cookie。
document.__defineGetter__("cookie", function() { return '';} );
document.__defineSetter__("cookie", function() {} );到目前为止,我有这个代码来检查用户是否允许cookie,
if(checkCookie != true){
// Run code to redefine cookie setter getter to prevent cookies from being set
}else{
// Don't do anything and the cookies should be run as usual.
};有没有人可以告诉我如何使用cookie setter和getter来做我已经解释过的事情,或者告诉我正确的方向?
发布于 2012-11-23 17:17:32
正如Alex Wayne对你的问题所说的那样,cookies甚至在你看到<html>标签进入你的浏览器之前就已经设置好了。
http是这样的:
HTTP/1.1 200 OK
Server: Nginx
Content-Length: x (size of the following content)
Content-Type: text/html (this is what identifies it as html)
Set-Cookie: foo=bar; expires=Tue, 4-Dec-2012 19:30:42 GMT; Max-Age=2592000; Path=/; Version="1"
<!DOCTYPE html>
<html>
...要执行这样的操作,您可以做的,也必须做的是设置一个“不要跟踪我”会话cookie,它告诉服务器不要将任何cookie放到所处理的请求上。
另一种方法是在地址栏中有一个get变量,它告诉服务器不要设置跟踪cookie。
实际上,这就是cookie的用途。
https://stackoverflow.com/questions/13525697
复制相似问题