Web NFC API
The readingerror event of the NDEFReader interface is fired whenever an error occurs during reading of NFC tags, e.g., when tags leave the reader's magnetic induction field.
Syntax
Use the event name in EventTarget/addEventListener:
addEventListener("readingerror", (event) => { })
Alternatively, assign to the event handler property of the interface:
onreadingerror = (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
Browser compatibility
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
