電子書籍の厳選無料作品が豊富!

jquery.cookie.jsを使用していますが、ページ遷移した際に、クッキーが外れるみたいなのです。
現象としては、文字サイズや背景色を変えて(別CSSを読み込む)同じ階層のページへ遷移してもそのまま文字サイズも背景色も適用されたままなのですが、別階層(index.htmlからlink/a.htmlなどフォルダ内のHTMLファイル)に遷移すると適用が外れます。そしてlink/a.htmlでサイズ変更してそこからindex.htmlに戻ると変えたはずの文字サイズなどは解除されています。
おそらくjquery.cookie.jsの問題かと思いますが、どこをいじればいいのか分かりません。
お願いします。
以下、jquery.cookie.jsのソースです。

jQuery.cookie = function (key, value, options) {

// key and value given, set cookie...
if (arguments.length > 1 && (value === null || typeof value !== "object")) {
options = jQuery.extend({}, options);

if (value === null) {
options.expires = -1;
}

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}

return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? String(value) : encodeURIComponent(String(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.secure ? '; secure' : ''
].join(''));
}

// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

A 回答 (1件)

jquery.cookie.jsの問題かと思いますが、どこをいじればいいのか分かりません。



=>「jquery.cookie.js」の機能が不足や不具合じゃないんだから、
これを改造するのは筋違いのアプローチだと思います。

使い方の問題だと思います。

Set the value of a cookie.

  $.cookie('the_cookie', 'the_value',
       {expires:7,path: '/',
       domain:'jquery.com',
       secure: true }
      );

 ※ path: '/' を省略せずにセットしましょう。
  確か、省略すると書き込んだページのパスでのみ有功だったような...

この回答への補足

さっそくのご回答ありがとうございます。
path: '/'はちゃんとセットしているのですが・・・。

なぜでしょうか・・・

補足日時:2010/11/11 12:48
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!