Gamepad: displayId property
WebVR API
WebVR API
The **`displayId`** read-only property of the Gamepad interface _returns the VRDisplay.displayId of the associated VRDisplay — the `VRDisplay` that the gamepad is controlling the displayed scene of._
A Gamepad is considered to be associated with a VRDisplay if it reports a pose that is in the same space as the display's pose, see VRDisplay.getPose().
> [!NOTE]
> This property was part of the old [WebVR API](https://immersive-web.github.io/webvr/spec/1.1/#gamepad-getvrdisplays-attribute). It has been superseded by the [WebXR Gamepads Module](https://immersive-web.github.io/webxr-gamepads-module/).
>
> There is no direct replacement for this property. The Gamepad object associated with an XRInputSource can be obtained using the XRInputSource.gamepad property.
## Value
A number representing the associated VRDisplay.displayId. If the number is 0, then the gamepad is not associated with a VR display.
## Examples
```js
window.addEventListener("gamepadconnected", (e) => {
if (!e.gamepad.displayId) {
console.log("Gamepad connected");
} else {
console.log(
`Gamepad connected, associated with VR display ${e.gamepad.displayId}`,
);
}
});
```
## Specifications
This property was part of the old [WebVR API](https://immersive-web.github.io/webvr/spec/1.1/#gamepad-getvrdisplays-attribute) that has been superseded by the [WebXR Gamepads Module](https://immersive-web.github.io/webxr-gamepads-module/). It is no longer on track to becoming a standard.
Until all browsers have implemented the new [WebXR APIs](/docs/Web/API/WebXR_Device_API/Fundamentals), it is recommended to rely on frameworks, like [A-Frame](https://aframe.io/), [Babylon.js](https://www.babylonjs.com/), or [Three.js](https://threejs.org/), or a [polyfill](https://github.com/immersive-web/webxr-polyfill), to develop WebXR applications that will work across all browsers. Read [Meta's Porting from WebVR to WebXR](https://developers.meta.com/vr/documentation/web/port-vr-xr/) guide for more information.
## Browser compatibility
## See also
- [WebVR API](/docs/Web/API/WebVR_API)
Cite this
"Gamepad: displayId property". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/displayId JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy