-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWebBluetoothFeatureDetect.html
More file actions
33 lines (32 loc) · 1019 Bytes
/
WebBluetoothFeatureDetect.html
File metadata and controls
33 lines (32 loc) · 1019 Bytes
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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
<body>
Web Bluetooth will be feature detected using script.
<script>
"use strict";
if (navigator.bluetooth) {
document.body.innerHTML =
"Web Bluetooth appears <strong>available</strong> via navigator.bluetooth." +
"<p><button onclick='requestDevice()'>Click to attempt a device request.</button>";
} else {
document.body.innerHTML =
"Web Bluetooth <strong>not available</strong> via navigator.bluetooth.";
}
function requestDevice() {
navigator.bluetooth.requestDevice(
{
filters: [{services: ['device_information']}]
}).then(requestDeviceSuccess, requestDeviceFailure);
}
function requestDeviceSuccess() {
document.body.innerHTML += "<p>requestDevice succeeded.";
}
function requestDeviceFailure(error) {
document.body.innerHTML += "<p>" + error.message;
}
</script>
</body>
</html>