ユーザーがネヌをクリックすると新しいウィンドウで開き、ユーザーがすでにそのメニューをウィンドウで開いている場合は、それにフォーカスするWebアプリケーションを作成します。これはタスクの簡単な部分です。メニューオプションのいずれかのキーを使用して、 window.open オブジェクトの配列を作成します。
function menuWindows(index, URL){
if (openedWindows.length < index){
openedWindows.length = index;
}
if ((openedWindows[index] == undefined) || openedWindows[index].closed){
openedWindows[index]= window.open(URL, index);
setOpenedWindows();
} else {
openedWindows[index].focus();
}
}
私の考えは、この配列を Cookie に保存し、Cookie から配列をロードするためのウィンドウが開いていることを確認する前にです。問題は、その配列をクッキーに保存しようとするときです。配列opendWindowsをCookieに保存する関数の最初のバージョンは次のとおりです。
function setOpenedWindows(){
$.cookie('openedWindows', JSON.stringify(openedWindows));
}
ブラウザ コンソールのエラーは次のとおりでした:「循環構造を JSON に変換しています」。ショット検索の後、この投稿を見つけました。ストア機能の 2 番目のバージョンは次のとおりです。
function setOpenedWindows(){
var cache = [];
var ow = JSON.stringify(openedWindows, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
return value;
});
cache = null; // Enable garbage collection
$.cookie("openedWindows", ow);
}
「Uncaught RangeError: Maximum call stack size exceeded」というエラーが表示され、どうすればよいかわかりません。