Web NFC aims to provide sites the ability to read and write to NFC tags when
they are brought in close proximity to the user’s device (usually 5-10 cm, 2-4
inches). The current scope is limited to NDEF, a lightweight binary message
format. Low-level I/O operations (e.g. ISO-DEP, NFC-A/B, NFC-F) and Host-based
Card Emulation (HCE) are not supported within the current scope.
Live Output
JavaScript Snippet
scanButton.addEventListener("click",async()=>{log("User clicked scan button");try{constndef=newNDEFReader();awaitndef.scan();log("> Scan started");ndef.addEventListener("readingerror",()=>{log("Argh! Cannot read data from the NFC tag. Try another one?");});ndef.addEventListener("reading",({message,serialNumber})=>{log(`> Serial Number: ${serialNumber}`);log(`> Records: (${message.records.length})`);});}catch(error){log("Argh! "+error);}});writeButton.addEventListener("click",async()=>{log("User clicked write button");try{constndef=newNDEFReader();awaitndef.write("Hello world!");log("> Message written");}catch(error){log("Argh! "+error);}});makeReadOnlyButton.addEventListener("click",async()=>{log("User clicked make read-only button");try{constndef=newNDEFReader();awaitndef.makeReadOnly();log("> NFC tag has been made permanently read-only");}catch(error){log("Argh! "+error);}});