useragent
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Component created
Component changed
Component body
This module adds some contextual body classes to the body tag on all pages showing
- Device type: desktop, tablet or phone
- Browser type: e.g. Firefox, Chrome, IE, Safari, Opera etc. (optional)
- Screen-size: e,g. x-small, small, medium, large, x-large etc.
- Local time of day: e.g. Configurable periods of day, morning, afternoon, evening, night
If geolocation is enabled, this module adds additional body classes for
- Country code: e.g. country-gb (UK), country-it (Italy), country-us (USA) etc..
- Configurable macro region (set of countries), e.g. region-mideast or region-euro
- Sun-up, sun-down: The geolocation component can calculate local time, sunrise and sunset times.
How can I use it?
By adding special body classes for device types or geographic regions, you can customise your theme to suit different devices, times of day and/or locales. Device type and geolocation are both detected client-side after page load, so the module will not customise or localise other aspects of your site, though you could build on this functionality to customise user experience via very simple methods:
- In your css:
body.region-australia { background-color: yellow; } body.region-europe { background-color: blue; } body.timeofday-morning { background-color: yellow; } body.timeofday-afternoon { background-color: orange; } body.timeofday-evening { background-color: red; } body.timeofday-right { background-color: black; } - In your custom JS (this must load after the user agent scripts):
if ( $('body').hasClass('country-ca')) { $('#message-pane').text("Welcome to all Canadian visitors"); }
Configuration
The module has an extensive configuration area at Admin > Configuration > Regional and Language > User Agent Customisation Settings. The overview page lets you enable and disable features and decide in which themes you wish to enable the plugin. This lets you define macro regions, times of day as well as user agent string used to match browsers and platforms.
Notes on Javascript Geolocation
If enabled, the geolocation script uses the like-named Javascript API which in most browsers will prompt user to allow location services. This message will only appear one. If this fails, the script will use a Web service to map the user agent's IP address with locale, usually this is their ISP's locale. This is not as accurate.
