HTMLScriptElement.supports()

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The supports() static method of the HTMLScriptElement interface provides a simple and consistent method to feature-detect what types of scripts are supported by the user agent.

The method is expected to return true for classic and module scripts, which are supported by most modern browsers.

Syntax

HTMLScriptElement.supports(type)

Parameters

type

A string literal that indicates the type of script for which support is to be checked. Supported values are case sensitive, and include:

  • "classic": Test if classic scripts are supported. "Classic" scripts are the normal/traditional JavaScript files that predate module scripts.
  • "module": Test if module scripts are supported.

Any other value will cause the method to return false.

Return value

Returns true if the indicated script type is supported and false otherwise.

Examples

The code below shows how to check if HTMLScriptElement.supports() is defined, and if so, to use it to test whether particular types of scripts are supported.

if (typeof HTMLScriptElement.supports == 'undefined') {
  //Check if method is defined
  log.textContent+="HTMLScriptElement.supports() method is not supported\n";
}
else
{
  //Returns true for the supported values
  log.textContent+="HTMLScriptElement.supports('module'): " + HTMLScriptElement.supports('module') +"\n";
  log.textContent+="HTMLScriptElement.supports('classic'): " + HTMLScriptElement.supports('classic') +"\n";

  //Returns false for any other values
  log.textContent+="HTMLScriptElement.supports('anything else'): " + HTMLScriptElement.supports('anything else') +"\n";
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
supports
No
No
94
No
No
No
No
No
94
No
No
No

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/supports