选择并聚焦现有窗口 [英] Select and focus an already existing window

查看:138
本文介绍了选择并聚焦现有窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经营一个电子商务网站,当客户提交订单时,我需要让这个弹出窗口正常工作。理想情况下,popop会在订单成功页面加载时出现,但弹出窗口阻止程序会停止此操作。

I run an e-commerce website, and I need to get this popup working when a client submits an order. Ideally, the popop would appear when the order success page loads, but popup blockers will stop this.

相反,当用户点击确认订单时,我会生成弹出窗口按钮,但这会在订单完成之前模糊结帐重定向到的3DSecure页面。

Instead, I generate the popup when the use clicks the "confirm order" button, but this obscures the 3DSecure page that the checkout redirects to before the order finishes.

为了抵消这一点,我在用户点击确认订单时创建弹出窗口,但立即重新聚焦主窗口;如果你愿意,可以选择一个pop-under。我的计划是从订单成功页面重新聚焦这个新窗口。

To counteract this, I create the popup when the user clicks "confirm order", but instantly refocus the main window; a pop-under if you will. My plan is to refocus this new window from the order success page.

问题是我找不到获取现有弹出窗口对象的方法,所以我可以运行关注它。如果我使用 window.open(url,windowName,options)创建窗口,有没有办法可以从其他页面引用它?按照 window.load(windowName)的说法是理想的。

The issue is that I cannot find a way to get the object for an existing popup so I can run the focus on it. if I create the window using window.open(url,windowName,options), is there a way I can reference that from another page? Something along the lines of window.load(windowName) would be ideal.

推荐答案

window.open的签名是这样的。

The signature of window.open is like this.

var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);

MDN注意到,


如果已存在名称为 strWindowName 的窗口,则 strUrl
加载到现有窗口中。在这种情况下,
方法的返回值是现有窗口,忽略 strWindowFeatures
strUrl 提供一个空字符串是一种方式,可以在不改变窗口位置的情况下通过名称获取对
打开窗口的引用。

If a window with the name strWindowName already exists, then strUrl is loaded into the existing window. In this case the return value of the method is the existing window and strWindowFeatures is ignored. Providing an empty string for strUrl is a way to get a reference to an open window by its name without changing the window's location.

所以这应该适合你。

window.open('', 'windowName', '');

根据MDN,只要打开一个窗口,就会创建对它的引用,

According to MDN whenever a window is opened a reference to it is created,

var windowObjectReference = window.open("http://www.google.com", "popup", "width=500,height=500");

您可以随时使用该参考加载它,例如

You could always load it using that reference like

if(windowObjectReference != null || !windowObjectReference.closed) {
    windowObjectReference .focus();
}

这篇关于选择并聚焦现有窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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