HIDDevice:productId 属性

Limited availability

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

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

备注: 此特性在 Web Worker(不包括共享 Web Worker)中可用。

HIDDevice 接口的 productId 只读属性返回已连接 HID 设备的产品 ID。

一个整数。如果设备没有产品 ID,或者无法访问产品 ID,则返回 0

示例

以下示例使用 HID.getDevices() 获取设备并将 productId 的值记录到控制台。

js
document.addEventListener("DOMContentLoaded", async () => {
  let devices = await navigator.hid.getDevices();
  devices.forEach((device) => {
    console.log(`HID:${device.productId}`);
  });
});

规范

Specification
WebHID API
# dom-hiddevice-productid

浏览器兼容性

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
productId
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.