setting cross-subdomain cookie with javascript

前端 未结 2 1028
情书的邮戳
情书的邮戳 2020-12-06 09:23

How should I add domain support to these functions? I want to achieve that .example.com is declared as domain, so that the cookies can be read across all subdomains of the e

2条回答
  •  执念已碎
    2020-12-06 10:00

    Here is a link on how to share cookies amongst a domain:

    https://www.thoughtco.com/javascript-by-example-2037272

    It involves setting the domain attribute of the cookie string like:

    document.cookie = "myValue=5;path=/;domain=example.com";
    

    This cookie should now be accessible to all sub domains of example.com like login.example.com

提交回复
热议问题