When js sets up cookie, how to set up .abc.com?

if I want a cookie to be able to use
under both www.abc.com and act.abc.com, I can write

when setting cookie.
document.cookie="name=value;path=/;domain=.abc.com";

the question is, now .abc.com is hard written in the code, is there any way to get the domain name dynamically?
I have tried document.domain, but this is to get www.abc.com and other things, can not get the domain name. Thank you

clipboard.png

Jun.06,2022

location.host

is the domain name of the web page automatically picked up


handle it yourself after you get the domain, depending on how many levels you want to set to the domain name.

Menu