Open In App

HTML DOM queryCommandSupported() Method

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

Syntax:



check = document.queryCommandSupported(command);

Parameters: This method accept single parameter command that holds the command for which we want to decide if the browser supports.

Return value:



Example 1: This example demonstrates the ueryCommandSupported() method when it returns true.

It will show if the command is supported or not, we will check for “SelectAll” command and then we will execute that command by execCommand() method.




<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM range
        queryCommandSupported() method
    </title>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <p>
        A<br>
        B<br>
    </p>
    <button onclick="sel()">Click</button>
  
    <script>
        function sel() {
            var check = document
                .queryCommandSupported("SelectAll");
            console.log(check);
  
            if (check) {
                document.execCommand(
                        "SelectAll", false, null);
            }
        }
    </script>
</body>
  
</html>

Output:

Example 2: In this example, this method will return “false” as the command is not be supported by the browser.




<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM range 
        queryCommandSupported() method
    </title>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <p>
        A<br>
        B<br>
    </p>
    <button onclick="sel()">Click</button>
  
    <script>
        function sel() {
            var check = document
                .queryCommandSupported("Select");
  
            console.log(check);
        }
    </script>
</body>
  
</html>

Output:

Supported Browsers: The browsers supported by DOM queryCommandSupported() method are listed below.


Article Tags :