Javascript chrome.tabs.query状态:正在加载->;例外?
我想为浏览器扩展名的Javascript chrome.tabs.query状态:正在加载->;例外?,javascript,google-chrome-extension,Javascript,Google Chrome Extension,我想为浏览器扩展名的chrome.tabs.query状态创建一个异常 我的代码当前如下所示: chrome.tabs.query({ "active": true, "currentWindow": true, "status": "loading", // <-- this line "windowType": "normal" }, ...); chrome.tabs.query({ “主动”:正确, “curr
chrome.tabs.query
状态创建一个异常
我的代码当前如下所示:
chrome.tabs.query({
"active": true,
"currentWindow": true,
"status": "loading", // <-- this line
"windowType": "normal"
}, ...);
chrome.tabs.query({
“主动”:正确,
“currentWindow”:正确,
“状态”:“正在加载”,//您可以将url:[]
属性添加到查询信息中,如下所示:
chrome.tabs.query({
"active": true,
"currentWindow": true,
"status": "complete",
"windowType": "normal",
"url": ["*://www.gmx.net/*", "*://www.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);
上面的代码将检查已完成加载的选项卡,但仅检查gmx.net或web.de上的选项卡
然后,您可以组合两个查询并使用相同的函数,如下所示:
chrome.tabs.query({
"active": true,
"currentWindow": true,
"status": "complete",
"windowType": "normal",
"url": ["*://www.gmx.net/*", "*://www.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);
为什么Firefox AdtAdtag?因为扩展可用于Chrome和Firefox:-不欢迎。如果我的答案解决了你的问题,然后考虑把它标记为正确,让其他有相同问题的人很容易找到它!