Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Sensor

Sensor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

TheSensor interface of theSensor APIs is the base class for all the other sensor interfaces. This interface cannot be used directly. Instead it provides properties, event handlers, and methods accessed by interfaces that inherit from it.

This feature may be blocked by aPermissions Policy set on your server.

EventTarget Sensor

When initially created, theSensor object isidle, meaning it does not take measures. Once thestart() method is called, it prepares itself to read data and, once ready, theactivate event is sent and the sensor becomesactivated. It then sends areading event each time new data is available.

In case of an error, theerror event is sent, reading stops, and theSensor object becomesidle again. Thestart() method needs to be called again before it can read further data.

Interfaces based onSensor

Below is a list of interfaces based on theSensor interface.

Instance properties

Sensor.activatedRead only

Returns a boolean value indicating whether the sensor is active.

Sensor.hasReadingRead only

Returns a boolean value indicating whether the sensor has a reading.

Sensor.timestampRead only

Returns the timestamp of the latest sensor reading.

Instance methods

Sensor.start()

Activates one of the sensors based onSensor.

Sensor.stop()

Deactivates one of the sensors based onSensor.

Events

activate

Fired when a sensor becomes activated.

error

Fired when an exception occurs on a sensor.

reading

Fired when a new reading is available on a sensor.

Specifications

Specification
Generic Sensor API
# the-sensor-interface

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp