Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How determine if the popup page is open or not?

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.

Thanks!

like image 347
Camilo Avatar asked Jan 19 '12 04:01

Camilo


People also ask

How to open popup window in html?

The syntax to open a popup is: window. open(url, name, params) : url. An URL to load into the new window.

How create popup window in JavaScript?

The width and height Parameters Width and height are the only required properties for a popup window. This line in our popup script creates a popup that is 400 wide and 200 high: window. open(href, windowname, 'width=400,height=200,scrollbars=yes');


1 Answers

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

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.

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.

like image 84
Adam Ayres Avatar answered Oct 10 '22 15:10

Adam Ayres