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 in secure contexts (HTTPS), in some or all supporting browsers.
The reading event is fired when a new reading is available on a sensor.
The Sensor interface is a base class, onreading and the reading event may only be used on one of the derived classes.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("reading", (event) => { })
onreading = (event) => { }
A generic Event with no added properties.
This example adds an event listener to read acceleration values of an Accelerometer. It reads sixty times a second.
const acl = new Accelerometer({ frequency: 60 });
acl.addEventListener("reading", () => {
console.log(`Acceleration along the X-axis ${acl.x}`);
console.log(`Acceleration along the Y-axis ${acl.y}`);
console.log(`Acceleration along the Z-axis ${acl.z}`);
});
acl.start();
| Specification |
|---|
| Generic Sensor API> # sensor-onreading> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
reading_event |
67 | 79 | No | 54 | No | 67 | No | 48 | No | 9.0 | 67 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Sensor/reading_event