2014-12-27 23 views
1

我想爲我的瀏覽器擴展的chrome.tabs.query狀態創建一個例外。chrome.tabs.query status:loading - > exception?

我的代碼目前看起來是這樣的:

chrome.tabs.query({ 
    "active":  true, 
    "currentWindow": true, 
    "status":  "loading", // <-- this line 
    "windowType": "normal" 
}, ...); 

www.gmx.netwww.web.de狀態應該是"complete"。任何人都可以告訴我如何能夠創建此異常?

+0

爲什麼火狐 - 插件標籤? – Noitidart 2014-12-28 06:36:27

+0

,因爲擴展程序可用於Chrome和Firefox :-) – 2014-12-29 13:29:01

回答

0

可以url: []屬性添加到查詢信息,像這樣:

chrome.tabs.query({ 
    "active":  true, 
    "currentWindow": true, 
    "status":  "complete", 
    "windowType": "normal", 
    "url": ["*://www.gmx.net/*", "*://www.web.de/*"] 
}, ...); 

上面的代碼將檢查已完成裝載片,但只有那些要麼在GMX。網web.de

然後,您可以將二者結合起來的查詢,並使用相同的功能,就像這樣:

function myFunction(tabs) { 
    if (~tab.url.indexOf('www.gmx.net') || ~tab.url.indexOf('www.web.de')) { 
     // the tab is on gmx.net or web.de and is complete 
    } else { 
     // the tab is not on gmx.net nor web.de and is still loading 
    } 
}; 

chrome.tabs.query({ 
    "active":  true, 
    "currentWindow": true, 
    "status":  "loading", 
    "windowType": "normal" 
}, myFunction); 

chrome.tabs.query({ 
    "active":  true, 
    "currentWindow": true, 
    "status":  "complete", 
    "windowType": "normal", 
    "url": ["*://www.gmx.net/*", "*://www.web.de/*"] 
}, myFunction); 
+0

非常感謝! – 2014-12-29 13:29:28

+0

不客氣。如果我的答案解決了您的問題,那麼請考慮將其標記爲正確,以讓其他遇到同樣問題的人輕鬆找到答案! – 2014-12-29 13:39:53