Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
40
rated 0 times [  46] [ 6]  / answers: 1 / hits: 16191  / 10 Years ago, wed, september 24, 2014, 12:00:00

I have a simple little script which I am using to set a cookie:



function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = expires=+d.toUTCString();
document.cookie = cname + = + cvalue + ; + expires;
}


The problem I have this cookie is only set on one page, not across the whole domain.



How can I adjust this function so that the cookie remains across the whole domain?


More From » jquery

 Answers
34

You can specifiy domain ;domain=.example.com as well as path ;path=/ (/ set cookie in whole domain)



document.cookie = cname + = + cvalue + ;  + expires +;path=/;

[#69346] Monday, September 22, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 4 Years ago
;