Multiple expiration options for a single cookie? (Javascript)

I was wondering if there is a way to set multiple expiration options for a single cookie. For example, I want the cookie to expire when the user closes the browser and after 30 minutes.

Is it possible?

YAHOO.util.Cookie.setSubs ("cookiename", cookieData, {expires: 0, expires: time () - 1800, path: "/", domain: "cbc.ca"});

+4
source share
2 answers

From RFC:

If an attribute appears more than once in a cookie, the behavior is undefined.

It is not possible to set a cookie like this; at least there is no cross-browser way to do this. (Also, as far as I know, the corresponding attribute is “Max-Age” and not “expiring”, perhaps this name is part of the YUI api.)

Ending a session after a certain period of time is usually what the secure server code does by itself and explicitly. (In other words, a session cookie is explicitly rejected as invalid if its timestamp indicates excessive age.)

+3
source

You can set a cookie for the onload event, but you cannot have two expiration dates. You can get the page load time and then set the cookie to +30 minutes. But you can’t set a cookie when the browser closes, for this you need a plugin, but when the page closes, you can.

+2
source

Source: https://habr.com/ru/post/1336820/


All Articles