2012-11-25 35 views
1

因此,我有一個父窗口,它將自己打開到一個新窗口(僅用於刪除狀態欄,工具欄和其他窗口)。關閉父窗口後,傳遞的變量返回空白字符串。有時會返回此錯誤消息:「遠程服務器計算機不存在或不可用。」即使在關閉父窗口之後,我真的需要訪問這個變量。有什麼建議麼?Javascript:關閉父窗口後無法訪問對象

var _env = {}; 
$(window).load(function() 
{ 
    /** 
    * 
    * If initialization was not yet performed, start the initialization. 
    * Otherwise, show application. 
    * 
    **/ 

    if (window.opener) 
    { 
     /* Start transition to the new window */ 
     window.blur(); 
     _env = window.opener._env; 

     console.log(_env["title"]); 

     /* Show system */ 
     window.opener.close(); 
     window.focus(); 

     console.log(_env["title"]); // Returns blank 
    } 
    else 
    { 
     /* Some process manipulating the '_env' variable */ 
     /* .... */ 
     /* .... */ 

     window.open("./index.html", _env["title"], "directories=0, menubar=0, toolbar=0, titlebar=0, resizable=1, width=" + _env["winWidth"] + ", height=" + _env["winHeight"]); 
     window.focus(); 
     window.open("","_self", ""); // To prevent prompt on closing.. 
    } 
}); 

回答

0

您可以將對象轉換爲JSON,並將其設置爲window.location.href。然後,您可以在需要數據時提取它,因爲您正在創建一個新對象,所以不會有任何引用問題。

+0

謝謝!這就像魔術一樣。 –