Take the 2-minute tour ×
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It's 100% free, no registration required.

Can we create a thorough question/answers post with the core methods that allow browser detection in Joomla 2.5 and 3 ? After a quick research in the web, I feel that there is not sufficient information on a single page the fulfills the topic.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

A more thorough walk through should really be added to the docs wiki IMO, but sharing what I can via mobile now.

For 2.5 and 3.x compatibility, you can use JBrowser to do some browser detection. However, this class may not work well with newer browsers or versions. To use it to get the browser:

$browser = JBrowser::getInstance()->getBrowser();

For 3.2 and newer, you can use JApplicationWebClient, which is a newer class designed to be more flexible with today's browser options. To use it to get the browser:

$client = JFactory::getApplication()->client->browser;

Both classes are documented on the API site, http://api.joomla.org/cms-3/index.html will link you to the base page for 3.3 docs.

share|improve this answer
3  
I would not use JBrowser, especially if you want to check if the device is mobile or not or what kind. It's really buggy. –  Valentin Despa May 7 at 7:25

In addition to Michael's answer, the JApplicationWebClient Class has a few other useful properties:

$client = JFactory::getApplication()->client;
$client->browser; // The detected browser used by the web client (returns an integer)
$client->browserVersion // The detected browser version used by the web client. (string)
$client->mobile // True if the web client is a mobile device (Boolean)
$client->platform // The detected platform on which the web client runs (integer)
$client->userAgent //The web client's user agent string. (string)
$client->robot // True if the web client is a robot (Boolean)

JApplicationWebClient Class API Documentation

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.