Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Content Translation Redirect Module content_translation_redirect crossed 1,000 active installs.

Browser Class

1,752 sites Security covered
View on drupal.org

This module helps theme developers create cross-browser compatible websites by adding browser and platform information as CSS classes to the body tag. It also provides tokens for including this browser information in error reports and allows developers to add custom classes.

Summary

This small module helps theme-developers to deal with cross-browser compatibility. It makes easier to handle different types of non-widespread browsers just as much as it helps with using different versions of Internet Explorer.
The module extends the $body_classes variable in page.tpl.php based on the enduser's browser, and platform.

The module also makes a $browser_classes variable available in page.tpl.php, which stores the data in an array, this way the developer can make use of it as needed, if he does not wish to use the $body_classes variable.

Supported browsers

  • ie
  • opera
  • safari
  • chrome
  • netscape
  • ff
  • konqueror
  • dillo
  • chimera
  • beonex
  • aweb
  • amaya
  • icab
  • lynx
  • galeon
  • operamini

Browser version checking

The module creates version classes.

  • ie[version]
  • opera[version]
  • chrome[version]
  • safari[version]
  • netscape[version]
  • ff[version]
  • konqueror[version]
  • operamini[version]

Supported platforms

  • win
  • ipad
  • ipod
  • iphone
  • mac
  • android
  • linux
  • nokia
  • blackberry
  • NetBSD
  • FreeBSD
  • OpenBSD

Mobile detecting

The module checks if the device is mobile and adds "mobile" or "desktop" class.

Token support

The module creates tokens, which will be greatly helpful when a user reports a site problem and a site administrator will receive a message with details regarding the user, including his/her browser class .
See the full discussion at #1052858: token for user's browser.

Currently available tokens

  • The current user's browser classes: [browserclass]
  • Browser type: [browserclass-browser]
  • Platform: [browserclass-platform]
  • Device info: [browserclass-mobile]
  • Extra hook classes: [browserclass-hook-classes]

Configuration

The module has a settings page, where the administrator can choose between these options:

  • always add the class with JavaScript
  • only use JavaScript if page cache is enabled

This is a fallback option for JS disabled browsers, and no JavaScript will run on page load if it's not necessary.

Example

In html:

<body class="... chrome chrome11 mac desktop">
...
</body>

In css:

body.chrome.mac p {
  font-size: 11px;
}

Developers

Developers can add their own classes with hook_browserclass_classes().

Activity

Total releases
1
First release
Dec 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Release date
8.x-1.1 Stable Dec 6, 2024