NDEFReader: reading event
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The reading
event of the NDEFReader
interface is fired whenever a new reading is available from compatible NFC devices (e.g. NFC tags supporting NDEF) when these devices are within the reader's magnetic induction field.
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener('reading', event => { });
onreading = event => { };
Event type
A generic Event
.
Examples
The following example shows how to process events using both the onreading
and onreadingerror
event handlers.
const ndef = new NDEFReader();
ndef.scan().then(() => {
console.log("Scan started successfully.");
ndef.onreadingerror = (event) => {
console.log("Error! Cannot read data from the NFC tag. Try a different one?");
};
ndef.onreading = (event) => {
console.log("NDEF message read.");
};
}).catch(error => {
console.log(`Error! Scan failed to start: ${error}.`);
});
Specifications
No specification found
No specification data found for api.NDEFReader.reading_event
.
Check for problems with this page or contribute a missing spec_url
to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.
Browser compatibility
No compatibility data found for api.NDEFReader.reading_event
.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.