开发者

Multiple expire options for one cookie? (javascript)

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

Is this possible?

YAHOO.开发者_运维知识库util.Cookie.setSubs("cookiename", cookieData, { expires: 0, expires: time() - 1800, path: "/", domain: "cbc.ca" });


From the RFC:

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

There's no way to set up a cookie to expire like that; at least, there's no cross-browser way to do it. (Also, as far as I know the appropriate attribute is "Max-Age", not "expires"; maybe that name is part of the YUI api however.)

Expiring a session after a period of time is generally something that secure server-side code does on its own, and explicitly. (In other words, the session cookie is explicitly rejected as invalid if its timestamp indicates excessive age.)


You can have the cookie set the onload event, but you can not have two expire times. You can get the time the page unloads and then set the cookie for +30 minutes. But you Cant have the cookie set when the browser closes, you would need a plugin to do that, but when the page closes you can.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜