When does a cookie with expiration time 'At end of session' expire?

后端 未结 4 1295
情深已故
情深已故 2020-12-15 02:18

There is a session cookie with expiration time which says \'At end of session\'. When exactly does it expire or will it be alive forever?

4条回答
  •  再見小時候
    2020-12-15 02:44

    Just to correct mingos' answer:

    If you set the expiration time to 0, the cookie won't be created at all. I've tested this on Google Chrome at least, and when set to 0 that was the result. The cookie, I guess, expires immediately after creation.

    To set a cookie so it expires at the end of the browsing session, simply OMIT the expiration parameter altogether.

    Example:

    Instead of:

    document.cookie = "cookie_name=cookie_value; 0; path=/";
    

    Just write:

    document.cookie = "cookie_name=cookie_value; path=/";
    

提交回复
热议问题