Ryan
Ryan

Reputation: 10049

Javascript, Chrome Extension development, close popup

In my manifest i have this:

"popup": "1_options.html"

and in the above html file I have this code

  var saved_email = localStorage['saved_email'];
  if (saved_email !== undefined ||  saved_email != "[email protected]") 
  {
      chrome.tabs.create({url: '0_register.html'});
  }

which is working exactly as I want, it opens a new tab with the register.html BUT it still has the popup open on the top right :( (1_options.html)

is there anyway to close the popup automatically as I open this new tab?

Thanks! Ryan

Upvotes: 0

Views: 1067

Answers (3)

netflux
netflux

Reputation: 3838

      chrome.tabs.create({url: '0_register.html', selected: true});

If you don't mind the new tab being selected when it is created, this also forces the popup to close.

Upvotes: 1

scurker
scurker

Reputation: 4753

There's several ways to do this, but the easiest is just to call:

window.close();

You can even do this in a callback function when you create your tab...

chrome.tabs.create({url: '0_register.html'}, function() {
  window.close();
});

You could also add a listener in your background script to check for tab updates, and if your new tab is your registration window, you could remove the popup:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
  if(changeInfo.status == "loading") {
      if(tab.url == "chrome-extension://[extension-id]/0_register.html") {
          chrome.tabs.remove(tabId);
      }
  }
});

Upvotes: 2

ChristopheCVB
ChristopheCVB

Reputation: 7315

Have you tried :

self.close();

Upvotes: 2

Related Questions