JavaScriptã§Cookieæä½
ä»äºã§JavaScriptã§Cookieæä½ãããã¨ã«ãªãã¯ããã¼ãæä½ããé¢æ°ãä½ã£ãã
jQueryã§æ¥½ã«å®è£
ã§ããããã ããä»åã¯ã©ã¤ãã©ãªã使ããªãæ¡ä»¶ã ã£ãã®ã§ã
ã¾ã ãã¡ãã¨ãã¹ããã¦ããªãã®ã§ãä½ããããã°ãããããã»ã»ã»ã
/** * Cookieä¿å * key ã¯ããã¼å * val ã¯ããã¼ã®å¤ */ function setCookie(key, val) { limitDate = new Date(); //æå¹æé(2é±é) limitDate.setTime(limitDate.getTime() + (24 * 60 * 60 * 30 * 1000)); tmp = key + '=' + escape(val) + '; '; tmp += 'path=/; '; tmp += 'expires=' + limitDate.toGMTString() + '; '; document.cookie = tmp; } /** * Cookieåå¾ * key ã¯ããã¼å * return ã¯ããã¼åã«è©²å½ããCookieã®å¤ */ function getCookie(key){ var tmp = document.cookie + ';'; var index1 = tmp.indexOf(key, 0); if(index1 != -1){ tmp = tmp.substring(index1,tmp.length); var index2 = tmp.indexOf('=',0) + 1; var index3 = tmp.indexOf(';',index2); return(unescape(tmp.substring(index2,index3))); } return(''); } /** * Cookieåé¤ * key ã¯ããã¼å */ function deleteCookie(key) { var limitDate = new Date(); limitDate.setYear(limitDate.getYear() - 1); var tmp = key + '=; '; tmp += 'path=/; '; tmp += 'expires=' + limitDate.toGMTString() + '; '; document.cookie = tmp; }