HTML - DOM Node isSupported() 方法



isSupported() 方法用於檢查 Web 瀏覽器是否支援或能夠處理網頁上的特定功能。

isSupported() 方法已過時,不建議使用。

語法

node.isSupported(feature, version)

引數

引數 描述
feature 指定要在網頁上檢查的功能名稱。
版本 指示功能的版本。

返回值

此方法返回布林值:如果支援該功能,則返回“true”;否則返回“false”。

HTML DOM 元素 'isSameNode()' 方法示例

以下是 isSameNode() 方法的一些示例,展示了此方法以前是如何使用的。

檢查 onclick 功能支援

此示例演示如何使用 isSupport() 方法檢查瀏覽器是否支援特定功能。

<!DOCTYPE html>
<html lang="en">
<head> 
    <title>isSupported() Method Example</title>
</head>

<body>
    <h1>HTML - DOM Element</h1>
    <h2>isSupported() Method</h2>
    <p>
        Click the button below to check if the onclick
        feature is supported by your browser.
    </p>
    
    <div>
    <button onclick="checkSupport()">Check Support</button>
    </div>
    <p><b>Note</b>: onclick event is note working  on IE 
       and  chrome but it is working fine in firefox.
    </p>

    <script>
    function checkSupport() {
        // Feature to check (example: onclick attribute)
        var feature = 'onclick';

        if (document.body.isSupported && 
        document.body.isSupported(feature)) {
        alert('Feature "' + feature + '" is supported!');
        } else {
        alert('Feature "' +feature+'"is not supported.');
        }
    }
    </script>
</body>
 
</html>

檢查剪貼簿功能支援

此示例演示如何使用 isSupport() 方法檢查瀏覽器是否支援特定功能。

<!DOCTYPE html>
<html lang="en">
<head> 
  <title>Checking for Feature Support</title>
</head>

<body>
  <h1>HTML - DOM Element</h1>
  <h2>isSupported() Method</h2>
  <p>
    Click the button below to check if the clipboard
    API feature is supported by your browser.
  </p>
  
  <div>
    <button onclick="checkSupport()">Check Support</button>
  </div>
  <p>
    <b>Note:</b>This feature is supported in 
    some browsers but not in older versions of others.
  </p>
  <script>
    function checkSupport() {
      var feature = 'clipboard';  
      if (document.body.isSupported && 
      document.body.isSupported(feature)) {
        alert('Feature "' + feature + '" is supported!');
      } else {
        alert('Feature "' + feature + '" is not supported.');
      }
    }
  </script>
</body>

</html>

支援的瀏覽器

方法 Chrome Edge Firefox Safari Opera
isSupported()
html_dom_element_reference.htm
廣告