如何确定弹出页面是否打开? [英] How determine if the popup page is open or not?

查看:75
本文介绍了如何确定弹出页面是否打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Chrome扩展程序,正在寻找如何(从后台页面)确定弹出页面是否打开.我调查了消息传递,但不确定是否能帮助我还是有更简单的方法.

I'm working on a Chrome extension and I'm looking how to find out (from the background page) if the popup page is open or not. I looked into message passing but I'm not sure if that's gonna help me at this or if there's a simpler way.

谢谢!

推荐答案

如果打开了弹出视图,则可以从后台页面获取以下chrome API调用:

You can use the following chrome API call from your background page fetch if the popup view is open:

var views = chrome.extension.getViews({ type: "popup" });

//views => [] //popup is closed
//views => [DOMWindow] //popup is open

如果它返回一个空数组,则您的弹出窗口未打开;如果它返回一个带有您的弹出窗口DOMWindow对象的数组,则您的弹出窗口处于打开状态.

If it returns an empty array then your popup is not open, if it returns an array with your popups DOMWindow object, then your popup is open.

如果一个插件中有多个弹出窗口,则可以检查返回的DOMWindow中是否存在某些全局变量以消除歧义.

If you have multiple popups in one plugin then you could check for the existence of some global variable in the returned DOMWindow to disambiguate.

这篇关于如何确定弹出页面是否打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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