0
我想在用戶不使用chrome(例如5分鐘後)時觸發一個方法,並在用戶變爲活動狀態時觸發另一個方法。這個怎麼做?如何檢測用戶在Chrome中的不活動?
我想在用戶不使用chrome(例如5分鐘後)時觸發一個方法,並在用戶變爲活動狀態時觸發另一個方法。這個怎麼做?如何檢測用戶在Chrome中的不活動?
Chrome有一個專用API chrome.idle來檢測閒置狀態。
chrome.idle.queryState(
5 * 60, // seconds
function(state) {
if (state === "active") {
// Computer not locked, user active in the last 5 minutes
} else {
// Computer is locked, or the user was inactive for 5 minutes
}
}
);
它還提供了一個事件,chrome.idle.onStateChanged
,通知您的狀態變化時。如果您想知道用戶是否在瀏覽器窗口中處於非活動狀態,您可以看到這篇文章 - Is there a way to detect if a browser window is not currently active?
謝謝。我正在chrome.tabs中尋找它。 – SKG