开发者

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 != "a@a.com") 
  {
      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 anyw开发者_开发百科ay to close the popup automatically as I open this new tab?

Thanks! Ryan


Have you tried :

self.close();


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);
      }
  }
});


      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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜