All the opened browser window should be redirect to a default page after inacivity

丶灬走出姿态 提交于 2020-01-25 06:42:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!