查找以前由window.open打开的窗口 [英] Find window previously opened by window.open

查看:233
本文介绍了查找以前由window.open打开的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到以下情况:从单个域运行:

We've got the following situation, running from a single domain:

页面A使用 window.open()打开命名窗口(弹出播放器)。 window.open()为页面A提供对窗口的引用。

Page A uses window.open() to open a named window (a popup player). window.open() gives page A a reference to the window.

用户现在重新加载页面A.参考到命名的窗口丢失了。使用 window.open()来查找窗口有重新加载它的不幸副作用(不合需要)。有没有其他方法可以获得对此窗口的引用?

User now reloads page A. The reference to the named window is lost. Using window.open() to "find" the window has the unfortunate side effect of reloading it (undesirable). Is there any other way to get a reference to this window?

推荐答案

试试这个:

var playerUrl = 'http://my.player...';
var popupPlayer= window.open('', 'popupPlayer', 'width=150,height=100') ;
if(popupPlayer.location.href == 'about:blank' ){
    popupPlayer.location = playerUrl ;
}
popupPlayer.focus();

它将打开一个具有唯一名称的空白窗口。由于url为空白,因此不会重新加载窗口的内容。

It will open a blank window with a unique name. Since the url is blank, the content of the window will not be reloaded.

这篇关于查找以前由window.open打开的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆