onvrdisplayconnect
is the name of the event listener property; the name of the event is just vrdisplayconnect
. So you can do either:
window.onvrdisplayconnect = e => console.log;
// Similar thing but you can have multiple listeners wired up at once.
window.addEventListener('vrdisplayconnect', e => console.log(e));
Most (all?) DOM events are named this way.
Note, WebVR has been superseded by WebXR. The new API has an event for a device changes, but typically you just start a session with navigator.xr.startSession('immersive-vr')
and when the Promise resolves the session has started. Listen to the "end" event for when the session ends.