Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. HTTP
  3. Reference
  4. Headers
  5. Permissions-Policy
  6. geolocation

Permissions-Policy: geolocation directive

Limited availability

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

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

The HTTPPermissions-Policy headergeolocation directive controls whether the current document is allowed touse theGeolocation Interface.

Specifically, where a defined policy blocks use of this feature, calls togetCurrentPosition() andwatchPosition() will cause those functions'callbacks to be invoked with aGeolocationPositionError code ofPERMISSION_DENIED.

Syntax

http
Permissions-Policy: geolocation=<allowlist>;
<allowlist>

A list of origins for which permission is granted to use the feature. SeePermissions-Policy > Syntax for more details.

Default policy

The default allowlist forgeolocation isself. The top-level browsing context and same-origin iframes are allowed access to thegeolocation feature by default.

Examples

Basic usage

SecureCorp Inc. wants to disallowgeolocation within all cross-origin iframes except those whose origin ishttps://example.com. It can do so by delivering the following HTTP response header to define a Permissions Policy:

http
Permissions-Policy: geolocation=(self "https://example.com")

SecureCorp Inc. must also include anallow attribute on each<iframe> element wheregeolocation is to be allowed:

html
<iframe src="https://example.com/map" allow="geolocation"></iframe>

Note:Specifying thePermissions-Policy header in this manner disallowsgeolocation for other origins, even if they are allowed by the<iframe>allow attribute.

Using the default policy

If an allowlist forgeolocation is not defined by aPermissions-Policy response header, user agents will apply the default allowlistself. In this mode,geolocation is automatically allowed in the top-level browsing context and same-origin iframes, but not in cross-origin iframes.

To allowgeolocation in a cross-origin iframe, include anallow attribute on the<iframe> element:

html
<iframe src="https://other.com/store-locator" allow="geolocation"></iframe>

Specifications

Specification
Geolocation
# permissions-policy

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp