2011-07-02 22 views
1

我只想從背景頁面創建一個新窗口並將其放回。我嘗試着重點:假,但它似乎並沒有成功。我試圖保存以前的windowId和tabId並在創建新窗口後更新它,但它也不能解決問題。創建一個窗口chrome,但後面有例外

你知道我們該怎麼做嗎?

這裏是我的代碼:

function saveTabId() { 
    // Get the current tab 
    chrome.tabs.getSelected(null,function(tab){ 
     if (tab != 'undefined') { 
      if (tab.windowId != windowId) { 
       currentTabId = tab.id; 
       currentWindowId = tab.windowId; 
      } 

      chrome.windows.create({url:"http://www.google.com", width:100,  height:100, top:0, left:0, focused:false}, function() { 

       chrome.tabs.get(currentTabId, function(tab) { 
       chrome.windows.update(tab.windowId, {}, function(w) { 
        chrome.tabs.update(tab.id, {selected:true}); 
       }); 
       }); 

      }); 

     } 

    }); 
} 

我發起這個代碼在background.html的開始,當我刷新了擴展,窗口是在擴展選項卡上。

PS:更奇怪的是,窗口位於擴展選項卡頂部,當我更改此窗口中的選項卡時,即使我單擊並在另一個窗口中鍵入文本,新窗口也會保持在另一窗口的頂部。 。

回答

0

謝謝,這是我現在使用的代碼。問題代碼中的問題是在更新之前將焦點放在其他窗口上。奇怪的是,當你專注於一個窗口時,它不會顯示在其他窗口之上。

function focusTab(tabId) { 
    chrome.tabs.get(tabId, function(tab) { 
     chrome.windows.update(tab.windowId, {}, function(w) { 
      chrome.tabs.update(tab.id, {selected:true}); 
     }); 
    }); 
} 
0

我把它種工作,但彈出窗口仍然顯示了片刻之前,在當前窗口的下面去:

chrome.windows.create({url:"http://www.google.com", width:100, height:100, top:0, left:0, focused:false}, function() { 
    chrome.windows.update(currentWindowId, {focused:true}); 
}); 
+0

謝謝,我不知道是否有可能直接在另一個下面...我只是在下一個答案中添加,重點放在良好的選項卡上,但實際上並不是必需的: ) – Farf