/
index.md
48 lines (35 loc) · 1.45 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
title: "NDEFRecord: mediaType プロパティ"
short-title: mediaType
slug: Web/API/NDEFRecord/mediaType
l10n:
sourceCommit: ef75c1741b450c2331204be5563ee964ad5f4c48
---
{{SecureContext_Header}}{{SeeCompatTable}}{{APIRef("Web NFC API")}}
**`mediaType`** は {{DOMxRef("NDEFRecord")}} インターフェイスのプロパティで、このレコードの {{Glossary("MIME type", "MIME タイプ")}}を返します。この値は `recordType` が `"mime"` と等しくない場合は `null` になります。
## 構文
```js-nolint
NDEFRecord.mediaType
```
### 値
文字列で、このレコードのペイロードの {{Glossary("MIME type", "MIME タイプ")}}が入ります。
## 例
次の例は {{domxref("NDEFReadingEvent.message")}} から取得した {{domxref("NDEFMessage")}} オブジェクト内のレコードを反復処理します。そして、 `mediaType` プロパティを使用して、どのレコードを解釈するかを決定します。
```js
const ndef = new NDEFReader();
await ndef.scan();
ndef.onreading = (event) => {
const decoder = new TextDecoder();
for (const record of event.message.records) {
if (record.mediaType === "application/json") {
const json = JSON.parse(decoder.decode(record.data));
const article = /^[aeio]/i.test(json.title) ? "an" : "a";
console.log(`${json.name} is ${article} ${json.title}`);
}
}
};
```
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}