Retrieve child window reference after refresh

后端 未结 5 1656
小鲜肉
小鲜肉 2021-01-17 18:32

I have an HTML5 offline app (i.e. there\'s no server-side component/code).

It basically has two windows (parent and child). However, in some instan

5条回答
  •  不要未来只要你来
    2021-01-17 19:15

    You can obtain the reference of child window simply by following trick.

    newWin = window.open("", "child_window_name", "width=...");
    if (newWin.location.href === "about:blank") {
        newWin = window.open("a.html", "child_window_name", "width=...");
    } else {
        // We've already obtained the reference.
        // However, IE and FireFox won't put focus on an already opened window.
        // So we have to do that explicitly:
        newWin.focus();
    }
    

    Note you must have a fixed child window name to make this trick works.

    Example URL: http://josephj.com/lab/2011/window-open-reconnect/demo.html

提交回复
热议问题