You are here: Reference > JavaScript > client-side > selection and ranges > methods > queryCommandSupported (document, TextRange, ...)

queryCommandSupported method (document, TextRange, ...)

Browser support:
Returns whether the specified command is supported by the current object.
The use of a non-supported command for the execCommand method raises an exception.
Note: the queryCommandSupported method is supported by Firefox, but it is not implemented and raises an exception.

Syntax:

object.queryCommandSupported (commandIdentifier);
You can find the related objects in the Supported by objects section below.

Parameters:

commandIdentifier
Required. A case-insensitive string that specifies the name of the command. See command identifiers for more information.

Return value:

Boolean. One of the following values:
false The specified command is not supported.
true The specified command is supported.

Example HTML code 1:

This example illustrates the use of the queryCommandSupported method:
<head>
    <script type="text/javascript">
        function TestCommands () {
                // try..catch is necessary because the queryCommandSupported method is supported but not implemented in Firefox.
            try {
                if (document.queryCommandSupported ("myCommand")) {
                    alert ("The 'myCommand' command is supported!");
                }
                else {
                    alert ("The 'myCommand' command is not supported!");
                }

                if (document.queryCommandSupported ("bold")) {
                    alert ("The 'bold' command is supported!");
                }
                else {
                    alert ("The 'bold' command is not supported!");
                }
            }
            catch (e) {
                alert ("Your browser does not support the queryCommandSupported method!");
            }
        }
    </script>
</head>
<body>
    <button onclick="TestCommands ();">Test whether some commands are supported!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content