Firefox Tomorrow

web api instance property

NDEFMessage: records property

View on MDN ↗

Secure contextLimited availability

The records property of NDEFMessage interface represents a list of NDEFRecords present in the NDEF message.

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 onreading, which is passed an instance of NDEFReadingEvent. An NDEFMessage object is returned from 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

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.