CdnXxRRODxX
CdnXxRRODxX

Reputation: 341

Is there a way to close a chrome extension popup, when the user is on a separate chrome window?

The scenario that I'm trying to get to work is:

If the user opens the extension popup on Chrome Window 1, and does not close the popup, the instant that the user opens another Chrome Window (Window 2) and starts working with it, I want the popup on Window 1 to close.

Basically, only the active Chrome Window can have the extension popup open.

Upvotes: 4

Views: 700

Answers (1)

Xan
Xan

Reputation: 77591

Hm. I didn't know the popups worked this way!

But yes, it's possible. You can use the chrome.extension.getViews() function to access all popups and close others.

So, at the beginning of your popup code, execute this:

chrome.extension.getViews({type: "popup"}).forEach(function(win) {
  if(win != window) win.close(); 
});

It's quite an ancient API (you can tell because it's synchronous) but still works.

Upvotes: 3

Related Questions