使用javascript保存Cookie如何指定域?
我正在使用此代码保存cookies:使用javascript保存Cookie如何指定域?,javascript,Javascript,我正在使用此代码保存cookies: function saveCookie(name,value) { var date = new Date(); date.setTime(date.getTime()+(60*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); document.cookie = name+"="+value+expires+"; pa
function saveCookie(name,value) {
var date = new Date();
date.setTime(date.getTime()+(60*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
document.cookie = name+"="+value+expires+"; path=/";
}
我的问题是它将cookie保存在domain example.com中,我想将它们写入.example.com,这样我也可以从子域中读取它们。这很容易用PHP实现,但我不知道如何用javascript实现。保存cookie时,如何在域前添加点?您已经在其中有路径,域也是以相同的方式指定的。要允许从其他子域读取,请尝试:
'; path=/; domain=.'+window.location.host;
路径的可能重复项=/;域=.+window.location.host?