2012-01-24 15 views
6

Uzantılar simgesi tıklandığında bir window.open() işlevi gören bir Chrome Uzantım var. (Chrome'daki alakasız bir hata nedeniyle geleneksel Chrome uzantısı açılır penceresini kullanamaz). Zaten açıksa bir pop-up pencereye odaklanmanın bir yolu olup olmadığını merak ediyorum. Chrome, window.focus() öğesini devre dışı bırakır, ancak bir Chrome Uzantısında bunu yapmanın bir yolu olabileceğini düşündüm.Bir Chrome Uzantısı'ndan bir pop-up penceresine odaklanabiliyor musunuz

Güncelleme: ilgilenen herkes için bu benim arka plan sayfasında kullanılarak bitti kodudur:

yerine window.open() kullanmanın
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; 
    } 
}); 

cevap

İlgili konular