最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Set Cookie Path JavaScript - Stack Overflow

programmeradmin0浏览0评论

I want the code below to set the path to root, I understand I have to set / as the path value however this is not my code and I am not familiar with Javascript!

function setCookie(name, value, expires, path, domain, secure){

document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

I have tried editing the code as below but have been unsuccessful.

 setCookie(name, value, expires, path, domain, secure){

document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path="/") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

I want the code below to set the path to root, I understand I have to set / as the path value however this is not my code and I am not familiar with Javascript!

function setCookie(name, value, expires, path, domain, secure){

document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

I have tried editing the code as below but have been unsuccessful.

 setCookie(name, value, expires, path, domain, secure){

document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path="/") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
Share Improve this question asked Jan 24, 2014 at 9:58 HarryHarry 3712 gold badges5 silver badges15 bronze badges 1
  • check out this link stackoverflow.com/questions/7551113/… – Mr.G Commented Jan 24, 2014 at 10:13
Add a comment  | 

1 Answer 1

Reset to default 14

change to this

function setCookie(name, value, expires, path, domain, secure){
    document.cookie= name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ("; path=/") +       //you having wrong quote here
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
发布评论

评论列表(0)

  1. 暂无评论