tknakatsu
8/15/2018 - 5:50 AM

get cookie value

vanilla js でクッキーの値を取得 参考:https://developer.mozilla.org/ja/docs/Web/API/Document/cookie

document.cookie = "test1=Hello";
document.cookie = "test2=World";

var cookieValue = document.cookie.replace(/(?:(?:^|.*;\s*)test2\s*\=\s*([^;]*).*$)|^.*$/, "$1");

function alertCookieValue() {
  alert(cookieValue);
}