Document: pointerlockchange event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The pointerlockchange
event is fired when the pointer is locked/unlocked.
The event handler can use Document.pointerLockElement
to determine whether the pointer is locked, and if so, to which element it is locked.
This event is not cancelable and does not bubble.
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
js
addEventListener("pointerlockchange", (event) => {});
onpointerlockchange = (event) => {};
Event type
A generic Event
.
Examples
Using addEventListener()
:
js
addEventListener("pointerlockchange", (event) => {
if (document.pointerLockElement)
console.log("The pointer is locked to: ", document.pointerLockElement);
else {
console.log("The pointer is not locked");
}
});
Using the onpointerlockchange
event handler property:
js
document.onpointerlockchange = (event) => {
if (document.pointerLockElement)
console.log("The pointer is locked to: ", document.pointerLockElement);
else {
console.log("The pointer is not locked");
}
};
Specifications
Specification |
---|
Pointer Lock 2.0 # pointerlockchange-and-pointerlockerror-events |
Pointer Lock 2.0 # dom-document-onpointerlockchange |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
pointerlockchange event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Requires a vendor prefix or different name for use.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.