javascript - Drupal - 如果关闭 JS,是否有特殊的 css 文件?

标签 javascript css drupal drupal-6 themes

我正在构建一个 Drupal 主题,想知道是否有一种 Drupalish 方法可以仅在用户关闭 js 的情况下添加 css 文件。

这最好放在 theme.info 文件中以保持整洁!

像这样的东西是理想的:

conditional-stylesheets[if no javascript][all][] = nojs.css

如果这不可能,那么我将把所有需要 JS 的 css 保留在 css 文件之外,并使用 JS 动态添加它,但这看起来有点困惑......

有什么想法吗?

最佳答案

您不需要条件注释或无脚本标签。默认情况下,Drupal 会向 html 元素添加一个“js”类,并在启用 javascript 时设置一个 cookie:

// Global Killswitch on the <html> element
if (Drupal.jsEnabled) {
  // Global Killswitch on the <html> element
  $(document.documentElement).addClass('js');
  // 'js enabled' cookie
  document.cookie = 'has_js=1; path=/';
  // Attach all behaviors.
  $(document).ready(function() {
  Drupal.attachBehaviors(this);
  });
 } 

(在/misc/drupal.js 中的第 296 行。)

所有只应在启用 js 时应用的 css 选择器,可以使用 .js 作为前缀。如果需要,您可以将这些 css 规则放在一个单独的文件中,但您不必这样做。

关于javascript - Drupal - 如果关闭 JS,是否有特殊的 css 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2896443/

相关文章:

html - 对于 html 电子邮件,电子邮件预览中显示哪些内容?

Drupal - 使用 PHP 代码隐藏 block

javascript - Rebol READ 自己如何实现异步可插拔协议(protocol)

javascript - 我如何使用 JSPDF 忽略 div which style = none

javascript - 在 onclick 函数中传递 id

CSS 基线网格 - 为什么行高变小而字体大小变大?

javascript - 如何在 onclick 事件上激活 "if"条件

Jquery MagicLine 使用背景图片?

drupal - 如何覆盖首页节点tpl-drupal

php - 创建一个新的社交网站。推荐的启动框架?