2012-01-24 22 views
6

拡張機能アイコンをクリックしたときにwindow.open()を実行するChrome拡張機能があります。 (Chromeの関連しないバグのため、従来のChrome拡張機能のポップアップは使用できません)。既に開いている場合は、ポップアップウィンドウをフォーカスする方法があるのだろうかと思います。 Chromeではwindow.focus()が無効になっていますが、Chrome拡張機能でその方法を実行する方法があると考えました。Chrome拡張機能からポップアップウィンドウを表示できます

更新:興味がある人々のために これは私が私の背景ページで使用して終了コードです:

代わりにwindow.open()を使用しての
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; 
    } 
}); 

答えて

8

はのchrome chrome.windows.createを使用するには.. http://code.google.com/chrome/extensions/windows.html#method-create
...コールバックでwindow.idを記録し、フォーカスを合わせたいときはいつでもchrome.windows.updateを使うことができます。

+0

乾杯、これは私が必要としていたものです。 –

関連する問題