HTMLScriptElement: noModule 屬性

HTMLScriptElement 介面的 noModule 屬性是一個布林值,用於指示指令碼是否應在支援 ES modules 的瀏覽器中執行。實際上,這可以用於為不支援 JavaScript 模組的舊瀏覽器提供備用指令碼。

它反映了 <script> 元素的 nomodule 屬性。

一個布林值,true 表示指令碼不應在支援 ES modules 的瀏覽器中執行,否則為 false

示例

html
<script id="el" nomodule>
  // If the browser supports JavaScript modules, the following script will not be executed.
  console.log("The browser does not support JavaScript modules");
</script>
js
const el = document.getElementById("el");
console.log(el.noModule); // Output: true

規範

規範
HTML
# dom-script-nomodule

瀏覽器相容性