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 onreading
property of the NDEFReader
interface is called 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.
The following example shows how to process events using both the onreading
and onreadingerror
event handlerss.
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}.`); });
Specification |
---|
Web NFC API # dom-ndefreader-onreading |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
onreading |
No |
No |
No |
No |
No |
No |
No |
89 |
No |
No |
No |
15.0 |
NDEFReader.onreadingerror
, property representing handler for readingerror
events.
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/NDEFReader/onreading