-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
53 lines (40 loc) · 1.37 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
49
50
51
52
53
---
title: "NDEFReadingEvent: serialNumber property"
short-title: serialNumber
slug: Web/API/NDEFReadingEvent/serialNumber
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.NDEFReadingEvent.serialNumber
---
{{securecontext_header}}{{APIRef}}{{SeeCompatTable}}
The **`serialNumber`** property of the {{domxref("NDEFReadingEvent")}} interface returns the serial number of the device, which is used for anti-collision and identification, or an empty string if no serial number is available.
## Value
A string containing the device's serial number.
## Examples
This example shows how to create a convenience function that reads a single tag and then stops polling, saving battery life by cutting unneeded work. The example could easily be extended to time out after a given amount of milliseconds.
```js
const ndefReader = new NDEFReader();
function read() {
return new Promise((resolve, reject) => {
const ctlr = new AbortController();
ctlr.signal.onabort = reject;
ndefReader.addEventListener(
"reading",
(event) => {
ctlr.abort();
resolve(event);
},
{ once: true },
);
ndefReader.scan({ signal: ctlr.signal }).catch((err) => reject(err));
});
}
read().then(({ serialNumber }) => {
console.log(serialNumber);
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}