Google chrome extension 你能从Chrome扩展集中弹出窗口吗

Google chrome extension 你能从Chrome扩展集中弹出窗口吗,google-chrome-extension,Google Chrome Extension,我有一个Chrome扩展,当单击扩展图标时,它会显示window.open()。(由于Chrome中存在一个不相关的错误,它无法使用传统的Chrome扩展弹出窗口)。我想知道如果弹出窗口已经打开,是否有办法聚焦它。Chrome禁用了window.focus(),但我认为有一种方法可以在Chrome扩展中实现 更新: 对于任何感兴趣的人,这是我在我的背景页面中使用的代码: var popupId; // When the icon is clicked in Chrome chrome.brow

我有一个Chrome扩展,当单击扩展图标时,它会显示window.open()。(由于Chrome中存在一个不相关的错误,它无法使用传统的Chrome扩展弹出窗口)。我想知道如果弹出窗口已经打开,是否有办法聚焦它。Chrome禁用了window.focus(),但我认为有一种方法可以在Chrome扩展中实现

更新: 对于任何感兴趣的人,这是我在我的背景页面中使用的代码:

var popupId;

// When the icon is clicked in Chrome
chrome.browserAction.onClicked.addListener(function(tab) {

  // If popupId is undefined then there isn't a popup currently open.
  if (typeof popupId === "undefined") {

    // Open the popup
    chrome.windows.create({
      "url": "index.html",
      "type": "popup",
      "focused": true,
      "width": 350,
      "height": 520
    }, function (popup) {
      popupId = popup.id;
    }); 

  } 
  // There's currently a popup open
  else {
     // Bring it to the front so the user can see it
    chrome.windows.update(popupId, { "focused": true });  
  }

});

// When a window is closed
chrome.windows.onRemoved.addListener(function(windowId) {
  // If the window getting closed is the popup we created
  if (windowId === popupId) {
    // Set popupId to undefined so we know the popups not open
    popupId = undefined;
  }
});

不要使用window.open()而是使用Chromes chrome.windows.create

…然后在回拨过程中,您可以录制它的window.id,然后,您可以在任何时候使用chrome.windows.update。

干杯,这正是我需要的。