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" : "");
}
In your Java server, you should call cookie. setPath("/") before adding it to response. Such cookie will match all request URIs.
You can't access cookies from a different path - otherwise it would be a security hole.
Change a Cookie with JavaScript With JavaScript, you can change a cookie the same way as you create it: document. cookie = "username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/"; The old cookie is overwritten.
Set a cookie path The path parameter specifies a document location for the cookie, so it's assigned to a specific path, and sent to the server only if the path matches the current document location, or a parent: document.
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" : "");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With