NDEFMessage.records

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

recordsNDEFMessage インターフェイスのプロパティで、 NDEF メッセージに現れる NDEFRecord のリストを表します。

NDEFRecord オブジェクトのリストで、メッセージに記録されたデータを表します。

次の例は、 NDEF メッセージの内容を読み取る方法を示しています。最初に onreading のイベントハンドラーをセットアップし、ここに NDEFReadingEvent のインスタンスが渡されます。 NDEFMessage オブジェクトが NDEFReadingEvent.message から返されます。このオブジェクトは message.records をループして、メッセージの種類に基づいて各レコードを処理します。 data メンバーは DataView であり、 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.
    }
  }
};

仕様書

Specification
Web NFC
# dom-ndefmessage-records

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
records
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.