Tôi có một Tiện ích mở rộng của Chrome thực hiện window.open() khi nhấp vào biểu tượng tiện ích mở rộng. (Không thể sử dụng cửa sổ bật lên Chrome truyền thống do lỗi không liên quan trong Chrome). Tôi tự hỏi nếu có một cách để tập trung một cửa sổ popup nếu nó đã được mở. Chrome tắt window.focus() nhưng tôi nghĩ có thể có cách để làm điều đó trong Tiện ích của Chrome.Bạn có thể tập trung cửa sổ bật lên từ Tiện ích mở rộng của Chrome
Cập nhật: Đối với bất cứ ai quan tâm này là mã tôi đã kết thúc sử dụng trong trang nền của tôi:
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;
}
});
Chúc mừng, đây chính xác là những gì tôi cần. –