如何用 JavaScript 建立僅限於會話的 Cookie?


要建立僅限於會話的 Cookie,你需要將 Cookie 的過期日期設定為之後的幾年。你需要設定 expire 屬性 −

current time + 5 years

expire 屬性顯示 Cookie 將過期的日期。如果此項為空,當訪客退出瀏覽器時 Cookie 就會過期。

注意 − 不要考慮移除 expire 值來建立僅限於會話的 Cookie。這不起作用。將 expire 屬性設定為將來的日期。

更新於: 16-Jun-2020

902 次檢視

啟動你的職業生涯

完成課程認證

立即開始
廣告
© . All rights reserved.