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 973261 of Document.queryCommandSupported()

  • Revision slug: Web/API/Document/queryCommandSupported
  • Revision title: Document.queryCommandSupported()
  • Revision id: 973261
  • Created:
  • Creator: Potappo
  • Is current revision? No
  • Comment deleted the spec of "queryCommandValue"

Revision Content

{{ApiRef("DOM")}}

The Document.queryCommandSupported() method reports whether or not the specified editor command is supported by the browser.

Syntax

isSupported = document.queryCommandSupported(command);

Parameters

command
The command for which to determine support.

Return value

Returns a {{jsxref("Boolean")}} which is true if the command is supported and false if the command isn't.

Notes

The 'paste' command return false not only if the feature is unavailable, but also if the script calling it has insufficient privileges to perform the action [1]

Example

var flg = document.queryCommandSupported("SelectAll");

if(flg) {
  // ...Do something
}

Specifications

Specification Status Comment
{{SpecName('HTML Editing','#querycommandsupported()','querycommandsupported')}} {{Spec2('HTML Editing')}} Initial definition

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 17 {{CompatGeckoDesktop("9.0")}}[1] 4.0 {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatGeckoMobile("9.0")}}[1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] Before Firefox 41, for the command 'paste' Firefox incorrectly returned true when the paste feature was available but the calling script had insufficient privileges to actually perform the action.

In Firefox, before Firefox 41, this was returning false. Now it returns true in user-initiated or privileged code.

See also

  • {{domxref("Document.execCommand()")}}
  • {{domxref("Document.queryCommandEnabled()")}}

Revision Source

<div>{{ApiRef("DOM")}}</div>

<p>The <code><strong>Document.queryCommandSupported()</strong></code> method reports whether or not the specified editor command is supported by the browser.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
<var>isSupported</var> = document.queryCommandSupported(<var>command</var>);
</pre>

<dl>
 <dt>
 <h3 id="Parameters">Parameters</h3>
 </dt>
 <dt><code>command</code></dt>
 <dd>The command for which to determine support.</dd>
</dl>

<h3 id="Return_value">Return value</h3>

<p>Returns a {{jsxref("Boolean")}} which is <code>true</code> if the command is supported and <code>false</code> if the command isn't<code>.</code></p>

<h2 id="Notes">Notes</h2>

<p>The <code>'paste'</code> command return <code>false</code> not only if the feature is unavailable, but also if the script calling it has insufficient privileges to perform the action <a href="#note1">[1]</a></p>

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

<pre class="brush:js">
var flg = document.queryCommandSupported("SelectAll");

if(flg) {
  // ...Do something
}
</pre>

<h2 id="Specifications">Specifications</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('HTML Editing','#querycommandsupported()','querycommandsupported')}}</td>
   <td>{{Spec2('HTML Editing')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</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</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>17</td>
   <td>{{CompatGeckoDesktop("9.0")}}<sup>[1]</sup></td>
   <td>4.0</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>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("9.0")}}<sup>[1]</sup></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Before Firefox 41, for the command <code>'paste'</code> Firefox incorrectly returned <code>true</code> when the paste feature was available but the calling script had insufficient privileges to actually perform the action.</p>

<p>In Firefox, before Firefox 41, this was returning <code>false</code>. Now it returns <code>true</code> in user-initiated or privileged code.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("Document.execCommand()")}}</li>
 <li>{{domxref("Document.queryCommandEnabled()")}}</li>
</ul>
Revert to this revision