您可以从Chrome扩展程序中关注弹出窗口吗?

Sea*_*ter 10 google-chrome-extension

我有一个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;
  }
});
Run Code Online (Sandbox Code Playgroud)

PAE*_*AEz 12

而不是使用window.open()使用Chromes chrome.windows.create ... http://code.google.com/chrome/extensions/windows.html#method-create
...然后在回电中你可以记录它的window.id,然后在你想要聚焦的任何时候你都可以使用chrome.windows.update.