scripting

Baseline 2023

Newly available

Since December 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

scripting CSS 媒体特性可以用来测试脚本(例如 JavaScript)是否可用。

语法

scripting 功能指定为从下面列表中选择的关键字值。

none

脚本在当前文档上完全不可用。

initial-only

脚本在最初的页面加载过程中被启用,但在之后则不被启用。

enabled

脚本是受支持的并在当前文档上激活。

示例

HTML

html
<p class="script-none">You do not have scripting available. :-(</p>
<p class="script-initial-only">
  Your scripting is only enabled during the initial page load. Weird.
</p>
<p class="script-enabled">You have scripting enabled! :-)</p>

CSS

css
p {
  color: lightgray;
}

@media (scripting: none) {
  .script-none {
    color: red;
  }
}

@media (scripting: initial-only) {
  .script-initial-only {
    color: red;
  }
}

@media (scripting: enabled) {
  .script-enabled {
    color: red;
  }
}

结果

规范

Specification
Media Queries Level 5
# scripting

浏览器兼容性

BCD tables only load in the browser

参见