jqueryでクライアント側のWebアプリケーションを開発しています
訪問したすべてのページを保存したいので、Cookie を使用します
したがって、保存する要素が 2 つあります。
- ページの URL
- ページタイトル
次のようにCookieでデータの作成を開始します。
インデックス.html:
if(!$.cookie("history")){
var url_history = document.location;
var title_history = $("html title").text();
$.cookie("historyURL", url_history);
$.cookie("historyTITLE", title_history);
}
anotherPage.html :
var url_history = document.location;
var title_history = $("html title").text();
$.cookie("historyURL", url_history);
$.cookie("historyTITLE", title_history);
問題は、Cookie の新しい値が古い値を上書きすることです。
次のような文字列ではなく、オブジェクトを設定する必要があると思います。
var objHistory = [];
objHistory.push({url:document.location, title: $("html title").text()})
$.cookie("history", objHistory);
今、私は別の問題を抱えています:
Cookie から My Object を取得できません
クッキーからオブジェクトを取得しようとすると、オブジェクトではなく文字列「オブジェクト」が表示されます
オブジェクトを Cookie に設定することはできますか?
お手伝いありがとうございます