不活动后所有打开的浏览器窗口应重定向到默认页面

问题描述 投票:0回答:1

当浏览器在给定时间内不活动时,我想重定向所有浏览器选项卡。

在此代码中,我将在“ theAppsString”中获取打开的应用程序/标签URL,然后如何获取其标签ID并将每个标签/ URL重定向到默认页面。

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')
          });

        });
      });
    });
  }
});
javascript browser
1个回答
0
投票

仅遍历选项卡。

示例(未试用):

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')
        });
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.