Bluetooth: availabilitychanged event
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 availabilitychanged event fires when the Bluetooth system as a whole becomes available or unavailable to the User Agent.
Syntax
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener('availabilitychanged', event => { });
onavailabilitychanged = event => { };
Event type
A generic Event.
Examples
To be informed when Bluetooth availability changes, you can add a handler to your Bluetooth instance using addEventListener(), like this:
Bluetooth.addEventListener("availabilitychanged", function(event) {
var availability = event.value;
});
Alternatively, you can use the Bluetooth.onavailabilitychanged event handler property to establish a handler for the availabilitychanged event:
Bluetooth.onavailabilitychanged = function(event) {
var availability = event.value;
}
Specifications
| Specification |
|---|
| Web Bluetooth # eventdef-bluetooth-availabilitychanged |
| Web Bluetooth # dom-bluetooth-onavailabilitychanged |
Browser compatibility
BCD tables only load in the browser