Md. Mahbubul Haque
Md. Mahbubul Haque

Reputation: 800

How can I close popup from background?

I know we can close a popup using window.close() from popup.

But is there any way to close the popup from the background page in a Chrome extension?

Upvotes: 1

Views: 941

Answers (1)

Xan
Xan

Reputation: 77482

It's possible with chrome.extension.getViews:

var windows = chrome.extension.getViews({type: "popup"});
if (windows.length) {
  windows[0].close(); // Normally, there shouldn't be more than 1 popup 
} else {
  console.log("There was no popup to close");
}

Upvotes: 3

Related Questions