Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 785721 of Permissions

  • Revision slug: Web/API/Permissions
  • Revision title: Permissions
  • Revision id: 785721
  • Created:
  • Creator: jpmedley
  • Is current revision? No
  • Comment

Revision Content

{{APIRef("Permissions API")}}{{SeeCompatTable}}

The Permissions interface of the Permissions API provides a method for querying the status of a user permission on the global scope.

Method

{{domxref("Permissions.query")}}
Returns the status of a user permission on the global scope.

Example

navigator.permissions.query({name:'geolocation'}).then(function(result) {
  if (result.status == 'granted') {
    showLocalNewsWithGeolocation();
  } else if (result.status == 'prompt') {
    showButtonToEnableLocalNews();
  }
  // Don't do anything if the permission was denied.
});

Specification

Specification Status Comment
{{SpecName('Permissions API', '#permissions-interface', 'Permissions')}} {{Spec2('Permissions API')}} Initial definition.

Browser Support

{{ CompatibilityTable() }}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(43.0)}} {{CompatUnknown()}} {{CompatUnknown()}} {{CompatUnknown()}} {{CompatUnknown()}}
Feature Android Chrome Mobile Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatNo()}} {{CompatChrome(43.0)}} {{CompatUnknown()}} {{CompatUnknown()}} {{CompatUnknown()}} {{CompatUnknown()}} {{CompatUnknown()}}

Revision Source

<p><span style="line-height: 19.0909080505371px;">{{APIRef("Permissions API")}}{{SeeCompatTable}}</span></p>

<p>The Permissions interface of the <a href="Permissions_API">Permissions API</a> provides a method for querying the status of a user permission&nbsp;on the global scope.</p>

<h2 id="Method">Method</h2>

<dl>
 <dt>{{domxref("Permissions.query")}}</dt>
 <dd>Returns the status of a user permission on the global scope.</dd>
</dl>

<h2 id="Example">Example</h2>

<pre class="brush: js">
navigator.permissions.query({name:'geolocation'}).then(function(result) {
  if (result.status == 'granted') {
    showLocalNewsWithGeolocation();
  } else if (result.status == 'prompt') {
    showButtonToEnableLocalNews();
  }
  // Don't do anything if the permission was denied.
});</pre>

<h2 id="Specification">Specification</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Permissions API', '#permissions-interface', 'Permissions')}}</td>
   <td>{{Spec2('Permissions API')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_Support">Browser Support</h2>

<div>{{ CompatibilityTable() }}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(43.0)}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome Mobile</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo()}}</td>
   <td>{{CompatChrome(43.0)}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
  </tr>
 </tbody>
</table>
</div>
Revert to this revision