Access a window by window name

后端 未结 7 1180
悲哀的现实
悲哀的现实 2020-11-29 07:08

If I open a window using

window.open(\'myurl.html\', \'windowname\', \'width=100,height=100\');

How do I refer to the new window (from the

7条回答
  •  没有蜡笔的小新
    2020-11-29 07:42

    Petr is correct:

    var w = window.open("", "nameofwindow");
    

    works in all browsers, I am using it to retrieve the reference to the window object previously opened by a different page. The only problem is the initial opening of the page, if the popup does not exist, you will get a new window with a blank page.

    I tried invoking a Javascript function inside the context of the other document in order to check whether I opened a new window or retrieved the already active page. If the check fails, I just invoke window.open again to actually load my popup content:

    var w = window.open("http://mydomain.com/myPopup", "nameofwindow");
    

    Hope that helps.

提交回复
热议问题