JavaScriptã§cookieãæä½ããæã¯jquery.cookie.jsã使ãã
âã§txtãã¡ã¤ã«ã¨ãã¦ãã¦ã³ãã¼ãã§ããã
http://plugins.jquery.com/project/cookie
使ãæ¹ã¯デモã触ã£ã¦ã¿ã¦ã½ã¼ã¹è¦ãã¨ãã
jquery.cookie.jsã®ã½ã¼ã¹ã®ã³ã¡ã³ãã®@exampleãè¦ãã¨ãããã°ããã¨æããã©ç°¡åã«èª¬æãã¦ããã¨ã
åºæ¬çã«ã¯$.cookie(ã¯ããã¼å);ã§å¤ã®åå¾ã$.cookie(ã¯ããã¼å,å¤);ã§å¤ã®è¨å®ãåºæ¥ã¦ã
第3å¼æ°ã§optionãããããæå®ã§ããã
$.cookie(ã¯ããã¼å,å¤,{ expires: æ¥æ°, path: '/', domain: ãã¡ã¤ã³});ã¨ãã
expiresãDateãªãã¸ã§ã¯ãã ããããªãã¦æ¥æ°ã®æ°å¤ã¨ãã¦ãæå®ã§ãã(ã¨ãããåºæ¬çã«ãã£ã¡ã使ãã¯ã)ã
jQuery pluginã ãã©$.é¢æ°åã§ä½¿ãé¢æ°ã§ããã
ä¾åãã¦ããjQueryã®æ©è½ãjQuery.trimé¢æ°ã ããªã®ã§ã
âã®ããã«2è¡å¤æ´ããã°jQueryéä¾åã®cookieæä½é¢æ°ã«å¤ããããã
@@ -53,7 +53,7 @@ * @cat Plugins/Cookie * @author Klaus Hartl/[email protected] */ -jQuery.cookie = function(name, value, options) { +cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { @@ -83,7 +83,7 @@ if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { - var cookie = jQuery.trim(cookies[i]); + var cookie = (cookies[i] || "").replace( /^\s+|\s+$/g, "" ); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
jQueryã¦ã¼ã¶ã«ãããã§ãªã人ã«ãã¨ã¦ããå§ã