JAB*_*JAB 2 drupal browser-detection drupal-6 drupal-7 drupal-modules
如何在Drupal 7中拥有特定于浏览器的css.如果浏览器是chrome,我想加载chrome.css.请帮忙
您可以使用preprocess_html主题钩子和drupal_add_css函数在template.php文件中执行此操作.
您将在drupal 7主题中找到示例,例如在bartik中:
// Add conditional stylesheets for IE
drupal_add_css(path_to_theme() . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
drupal_add_css(path_to_theme() . '/css/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 6', '!IE' => FALSE), 'preprocess' => FALSE));
Run Code Online (Sandbox Code Playgroud)
编辑:由于chrome 没有条件注释,您可以检查$ _SERVER ['HTTP_USER_AGENT']:
if (isset($_SERVER['HTTP_USER_AGENT'])
&& stripos($_SERVER['HTTP_USER_AGENT'], 'chrome')!==false) {
drupal_add_css( ... );
}
Run Code Online (Sandbox Code Playgroud)
但在此之前,请尝试修复您的CSS规则!