LoginSignup
1
0

More than 1 year has passed since last update.

jquery.cookie.js を使いたい。でも SameSiteに対応していない

Posted at

ご安心下さい。簡単な改造で jquery.cookie.js に samesiteに対応することができます。

CDNでは対応することができませんので、ソースをダウンロードします。

jquery.cookie.js(github)

その後、ソースに以下の部分を探す

jquery.cookie.js
            return (document.cookie = [
                encode(key), '=', stringifyCookieValue(value),

おおむね、以下のように変更する

jquery.cookie.js
            return (document.cookie = [
                encode(key), '=', stringifyCookieValue(value),
                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
                options.path    ? '; path=' + options.path : '',
                options.domain  ? '; domain=' + options.domain : '',
                options.sameSite  ? '; sameSite=' + options.sameSite : '',
                options.secure  ? '; secure' : ''
            ].join(''));

            options.sameSite  ? '; sameSite=' + options.sameSite : '',

を途中加わっていることがわかるかと思います

使い方

$.cookie("name", "value", {expires: 365, path: "/", sameSite: "lax"});
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0