Javascript:关闭父窗口后无法访问对象

时间:2012-11-25 08:12:54

标签: javascript jquery internet-explorer-8

所以我有一个父窗口,它将自己打开到一个新窗口(只是删除状态栏,工具栏,其他)。关闭父窗口后,传递的变量返回空白字符串。有时它会返回此错误消息:“远程服务器计算机不存在或不可用。”即使在关闭父窗口后,我确实需要访问此变量。有什么建议吗?

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..
    }
});

1 个答案:

答案 0 :(得分:0)

您可以将对象转换为JSON,并将window.location.href设置为它。然后,您可以在需要数据时将其提取出来,并且由于您正在创建新对象,因此引用不会出现任何问题。