guyeuro
V2EX  ›  问与答

关于 cookie max-age 的理解

  •  
  •   guyeuro · Jun 2, 2017 · 1610 views
    This topic created in 3293 days ago, the information mentioned may be changed or developed.

    假如服务器端设置一个 cookie 的 max-age 为 60 分钟 浏览器设置 cookie 后 过了 20 分钟 这个 max-age 在浏览器端会变成 40 吗? 也就是用 cookie.getMaxAge()的值是多少?

    另外,这个 max-age 是不是浏览器用来清除 cookie 用的 也就是 60 分钟后,浏览器清除这个 cookie ?

    Yuigahama
        1
    Yuigahama  
       Jun 2, 2017
    不会变
    cookie.getMaxAge 是什么
    ```
    VM1898:1 Uncaught TypeError: document.cookie.getMaxAge is not a function
    at <anonymous>:1:17
    ```

    cookie 是字符串,存储在浏览器里面不会变
    max-age 到期浏览器删除 cookie
    Yuigahama
        2
    Yuigahama  
       Jun 2, 2017
    搜了一下 cookie.getMaxAge 结果都是 java 相关的
    你想用 java 在服务器是无法获得存储在浏览器上 cookie 除 name value 对之外的信息的,因为浏览器发送请求的时候只会发送这个
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5582 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:34 · PVG 09:34 · LAX 18:34 · JFK 21:34
    ♥ Do have faith in what you're doing.