NDEFMessage.records

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 records property of NDEFMessage interface represents a list of NDEFRecords present in the NDEF message.

Syntax

var recordList = NDEFMessage.records;

Value

A list of NDEFRecord object that represent data recorded in the message.

Examples

The following example shows how to read the contents of an NDEF message. It first sets up an event handler for NDEFReader.onreading, which is passed an instance of NDEFReadingEvent. An NDEFMessage object is returned from NDEFReadingEvent.message. It loops through message.records and processes each record based on its message type. The data member is a DataView, which allows handling data encoded in UTF-16.

ndefReaderInst.onreading = event => {
  const ndefMessage = event.message;
  for (const record of ndefMessage.records) {
    console.log("Record type:  " + record.recordType);
    console.log("MIME type:    " + record.mediaType);
    console.log("Record id:    " + record.id);
    switch (record.recordType) {
      case "text":
        // TODO: Read text record with record data, lang, and encoding.
        break;
      case "url":
        // TODO: Read URL record with record data.
        break;
      default:
        // TODO: Handle other records with record data.
    };
  };
};

Specifications

Specification
Web NFC API
# dom-ndefmessage-records

Browser compatibility

BCD tables only load in the browser