scripting CSS media feature can be used to test whether scripting (such as JavaScript) is available.

句法

scripting feature is specified as a keyword value chosen from the list below.

none

Scripting is completely unavailable on the current document.

initial-only

Scripting is enabled during the initial page load, but not afterwards.

enabled

Scripting is supported and active on the current document.

范例

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

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;
  }
}
					

结果

规范

规范 状态 注释
Media Queries Level 5
The definition of 'scripting' in that specification.
编者草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
scripting media feature Chrome 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 489957 .
Edge 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 489957 .
Firefox 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 1166581 .
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 489957 .
Chrome Android 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 489957 .
Firefox Android 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 1166581 .
Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 489957 .

图例

不支持

不支持

见实现注意事项。

见实现注意事项。

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. CSS Conditional Rules
  4. Media Queries
  5. 指南
    1. Using feature queries
    2. Testing media queries programmatically
    3. Using Media Queries for Accessibility
    4. Using media queries
  6. At-Rules
    1. @document
    2. @import
    3. @media
    4. @supports

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1