Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set path while saving a cookie value in JavaScript?

I am saving some cookie values on an ASP page. I want to set the root path for cookie so that the cookie will be available on all pages.

Currently the cookie path is /v/abcfile/frontend/

Please help me.

like image 941
user959128 Avatar asked Sep 26 '11 05:09

user959128


People also ask

How do I set a cookie path?

cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; This statement will delete a cookie named “username” if one exists. Some browsers will not allow the deletion of a cookie if the path is not specified. Therefore, it is important to always specify the path when working with cookies.

Can I set cookie for another path?

You can't access cookies from a different path - otherwise it would be a security hole.

Are cookies path specific?

For those who didn't know, cookies are only accessible to the specified path and any subpaths, no superpaths. So cookies for the path "/folder/subfolder1/" are not accessible to "/folder/".


1 Answers

simply: document.cookie="name=value;path=/";

There is a negative point to it

Now, the cookie will be available to all directories on the domain it is set from. If the website is just one of many at that domain, it’s best not to do this because everyone else will also have access to your cookie information.

like image 186
Triptaminer Avatar answered Oct 09 '22 11:10

Triptaminer