不活动后,所有打开的浏览器窗口应重定向到默认页面 [英] All the opened browser window should be redirect to a default page after inacivity
本文介绍了不活动后,所有打开的浏览器窗口应重定向到默认页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当浏览器在给定时间内不活动时,我想重定向所有浏览器选项卡.
I want to redirect all the browser tabs when the browser is not active for given time.
在此代码中,我将在"theAppsString"中获取打开的应用程序/选项卡URL,然后如何获取其选项卡ID并将每个URL重定向到默认页面.
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')
});
});
});
});
}
});
推荐答案
只需遍历选项卡即可.
示例(未经测试):
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')
});
}
});
这篇关于不活动后,所有打开的浏览器窗口应重定向到默认页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文