Cookie代码不适用于Chrome [英] JavaScript code for cookie not working in Chrome

查看:133
本文介绍了Cookie代码不适用于Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在FF中正常工作:

  var date = new Date(); 
date.setTime(date.getTime()+(1 * 24 * 60 * 60 * 1000));
expires =; expires =+ date.toGMTString();
document.cookie =c_odi+=+ $('#orderdetailid')。val()+ expires +; path = /;

但不是在Chrome中。当我使用Chrome浏览器并在控制台中执行 document.cookie 查看cookie时, c_odi cookie不是'那里。但是当我在FF中也这样做时,情况就是如此。我们如何让Cookie在Chrome中工作?由PHP添加的cookies很好,但在JavaScript中没有这个,我确实需要通过JavaScript添加此cookie。

解决方案

如果您将代码打开为 file:/// C:/.../xxx.html 而不是<$ c $,则可能会出现此问题c> http:// localhost / xxx.html 。 Chrome不会在 file:// 情况下保存cookie(因为没有域名,也没有http通信)。



少数感兴趣的链接:


The following code works fine in FF:

var date = new Date();
date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
document.cookie = "c_odi" + "=" + $('#orderdetailid').val() + expires + "; path=/";

But not in Chrome. When I'm using Chrome and I do document.cookie in the console to view cookies, the c_odi cookie isn't there. But when I do the same in FF, it is. How can we make cookies work in Chrome? The cookies that were added by PHP are fine, but not this one in JavaScript, and I do need to add this cookie via JavaScript at this point.

解决方案

This problem can occur if You open Your code as file:///C:/.../xxx.html instead of http:// localhost/xxx.html. Chrome doesn't save cookies (because there is no domain and no http communication) in file:// case.

Few links of interest:

这篇关于Cookie代码不适用于Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆