问题
I want to redirect all the browser tabs when the browser is not active for given time.
In this code I will get the opened applications/tabs url in "theAppsString" then how can i get its tab id and redirect each to a default page.
chrome.idle.queryState(30, function(state) {
if (state === "active") {
console.log('Computer not locked, user active ');
} else {
console.log('sorry Computer not locked, user nopt active ');
chrome.storage.local.get("appsLog", function(obj) {
theAppsLog = obj.appsLog;
$.each(theAppsLog, function(index, element) {
theAppsString = element.app;
var queryInfo = {
active: false,
currentWindow: false
};
chrome.tabs.query(queryInfo, function(tabs) {
var tab = tabs[0];
var tabid = tab['id'];
chrome.tabs.update(tabid, {
active: false,
url: chrome.extension.getURL('html/onionid-ban-inactive-app.html')
});
});
});
});
}
});
回答1:
Just iterate over the tabs.
Example (untested):
chrome.tabs.query(queryInfo, function(tabs) {
for (var i = 0; i < tabs.length; i++) {
var tabid = tabs[i]['id'];
chrome.tabs.update(tabid, {
active: false,
url: chrome.extension.getURL('html/onionid-ban-inactive-app.html')
});
}
});
来源:https://stackoverflow.com/questions/59838971/all-the-opened-browser-window-should-be-redirect-to-a-default-page-after-inacivi