Navigator.addIdleObserver()

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译
您也可以阅读此文章的English (US)版。

Non-standard
This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.

This API is available on Firefox OS for internal applications only.

Summary

This method is used to add an observer that will check if the user is idle and will act accordingly. Once an observer is added, it can be removed with Navigator.removeIdleObserver.

Syntax

navigator.addIdleObserver(IdleObserver);

Parameters

IdleObserver
An object with specific properties to handle if the user is idle or not; see IdleObserver below.

IdleObserver

The IdleObserver is any object with the three following properties:

time
The time (expressed in seconds) before the user is considered idle.
onidle
A function called when the user is considered idle.
onactive
A function called when the user becomes active again.

Example

var myObserver = {
  time: 10,
  onidle: function () {
    console.log("The user is idle for 10 seconds");
  },
  onactive: function () {
    console.log("The user is now active again");
  }
}

navigator.addIdleObserver(myObserver);

Specification

Not part of any specification yet; however, this API will be discussed at W3C as part of the System Applications Working Group.

See also

文档标签和贡献者

此页面的贡献者: teoli, kscarfone, Sheppy, Jeremie, ztooner, sicking
最后编辑者: teoli,