Search code snippets, questions, articles...

Set a cookie for whole domain in javascript

In this post, we are going to describe the methods that can be used to set a cookie for the whole website or domain and not for some specific page.
document.cookie = "cookie_name=cookie_value;path=/";
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

When we set a cookie in javascript using document.cookie, it set the cookie for that specific page on which we are running the script. To set the cookie for the entire site we use path keyword with cookie name and cookie value and assign it '/' value.

Was this helpful?
0 Comments