新手问题 如何添加一个 Cookie 使用协议

Peter · October 10, 2014 · Last by est replied at October 11, 2014 · 4072 hits

现在打开很多网站都会在最上方弹出一个 notice,说我要在你的电脑上放 cookie,比如这个: http://www.oxforddictionaries.com/

这是怎么实现的? 第一次来访,没发现有 cookie 就出现这个信息条? 如果有 cookie 就不出现?

我觉得每次页面访问都要加个判断 cookie 的存在与否是不是不太好?

js 可以读写 cookie 的,应该是 js 实现的

你给的那个网站的实现...

$(document).ready(function () {
    if ($.cookie("cookieLaw") == null) {
        if ($("#popups").length == 0)
            $("body").prepend("<div id='popups'></div>");
        $("#popups").append('<div id="cookieLaw"><a id="cookieClose">×</a>We use cookies to enhance your experience on our website. By continuing to use our website, you are agreeing to our use of cookies. You can change your cookie settings at any time. <a class="cookieClosing"> Continue </a> or <a href="http://global.oup.com/cookiepolicy/?siteid=freeodo" target="_blank" title="How we use cookies on this site">Find out more</a></div>');
        $.cookie("cookieLaw", true, {path : "/", expires : 365});
        $(".cookieClosing, #cookieClose").click(function () {
            $("#cookieLaw").hide();
        });
    }
});

Cookie 不是读的,而是 HTTP 请求的时候自动往服务器提交的,所以没必要非得放到前端去取,直接服务端判断,并给出提示界面就好了。

这个是欧盟的规定。。。网站要用 cookie 必须显式提醒用户。。。略显蛋痛。

You need to Sign in before reply, if you don't have an account, please Sign up first.