HTMLGeolocationElement: validationstatuschange event
The validationstatuschange event of the HTMLGeolocationElement interface is fired whenever the <geolocation> element's isValid value changes.
This occurs as a result of a blocker being added to or removed from a <geolocation> element.
Syntax
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("validationstatuschange", (event) => { })
onvalidationstatuschange = (event) => { }
Event type
An Event.
Examples
>Using validationstatuschange to report invalid reasons
In our Exploring invalid reasons demo (source code), we use a validationstatuschange event handler to report when a <geolocation> element becomes valid, and report the invalid reason when it becomes invalid:
geo.addEventListener("validationstatuschange", () => {
if (geo.isValid) {
reasonElem.textContent = `<geolocation> is valid`;
} else {
reasonElem.textContent = `Invalid reason: ${geo.invalidReason}`;
}
});
Whenever the validation status changes, we check whether the <geolocation> element is valid using HTMLGeolocationElement.isValid, and if so, print a message confirming this to the <p> element text content. If the <geolocation> element is invalid, we print the HTMLGeolocationElement.invalidReason to the <p> element text content.
See the HTMLGeolocationElement.invalidReason page for a full walkthrough of this example.
Specifications
This feature does not appear to be defined in any specification.>Browser compatibility
See also
<geolocation>element