1. 程式人生 > >js cookie

js cookie

asc clas domain 所有 tex dom javascrip span 區分

js set cookie

<script type="text/javascript">
var cookieName = HelloWorld;
var cookieValue = HelloWorld;
var myDate = new Date();
myDate.setMonth(myDate.getMonth() + 12);
document.cookie = cookieName +"=" + cookieValue + ";expires=" + myDate 
                  + ";domain=.example.com;path=/
"; </script>

domain 可以設置所有域名包含有.example.com的網站

path 設置為 / 時,設置的cookie不區分路徑

js cookie