W3cubDocs

/Web APIs

NDEFMessage: records property

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.

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 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.

js

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
records No No No No No No 89 89 No 63 No 15.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/NDEFMessage/records