6
我有一個Chrome擴展程序,它在單擊擴展程序圖標時執行window.open()。 (由於Chrome中存在無關的錯誤,因此無法使用傳統的Chrome擴展程序彈出窗口)。我想知道如果有一種方法可以集中彈出窗口,如果它已經打開。 Chrome會禁用window.focus(),但我認爲Chrome擴展中可能會有這種方法。您可以專注於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;
}
});
乾杯,這正是我所需要的。 –