Menu Content

Currencies Accepted


Shopping Cart

cart
Your Cart is currently empty.

How to Download A Product

For most of our products, including the free ones, you will need to go through checkout and place an order.

Read More

 

Find Us Elsewhere

Follow us on Twitter

Spiral Scripts on Facebook

rapidssl_ssl_certificate
2Checkout.com is a worldwide leader in payment services

Google ads

Home » Joomla Tips » Browser Detection in Joomla

Browser Detection in Joomla PDF Print E-mail

It is often the case that as web developers we need to add some extra coding that will deal with the quirks of particular web browsers . Using Joomla we can take advantage of Joomla's built in browser detection.

Browser detection is handled through the JBrowser class. The is located in Joomla's class library, in the environment subpackage. In order to use it you will first need to import it:-

jimport('joomla.environment.browser');

Then you need to get an instance of the browser object

$browser = &JBrowser::getInstance();

You can then find information about the web browser being used through examing the properties of this object, which are accessed through the appropriate 'get' method. The methods include:-

  1. getPlatform: returns the browser platform ('win','mac' or 'unix');
  2. getBrowser: returns the browser type ('opera','palm','msie', 'amaya', 'fresco', 'avantgo', 'konqueror', 'mozilla', 'lynx', 'links', 'hotjava', 'up','xiino', 'palmscape', 'nokia', 'ericsson', 'wap', 'imode', 'blackberry', 'motorola', 'mml');
  3. getMajor: returns the major version number;
  4. getMinor: returns the minor version number.

To give an example, a very common application is that you wish to load a separate stylesheet for users of Internet Explorer 6, to deal with its annoying quirks.

Example

        jimport('joomla.environment.browser');
$doc =& JFactory::getDocument();
$browser = &JBrowser::getInstance();
$browserType = $browser->getBrowser();
$browserVersion = $browser->getMajor();
if(($browserType == 'msie') && ($browserVersion < 7))
{
$doc->addStyleSheet( 'css/ie6.css' );

}

If there is a particular quirk that you wish to deal with, such as lack of support for alpha transparency in png images (a common complaint with IE6), you can use the getQuirks() method:-

   If($browser->getQuirks('png_transparency'))
   {
        $doc->addScript( 'js/pngfix.js' );
   }

Other useful methods are:-

  1. isRobot(): returns true if the user agent is in fact a robot;
  2. isSSLConnection(): returns true if the connection is SSL.
  3. hasFeature('feature'): returns true if the browser supports the feature 'feature', which can include among others ('iframes', 'frames', 'javascript','java', 'images', 'dom, 'svg'')

Limitations

The browser object uses the reported user agent to detect this information, this information is under the control of the client so there is no guarantee that it is true. In particular you need to be careful using the hasFeature() method. For example the reported value for hasFeature('javascript') does not take account of the fact that users can choose to disable scripting on a browser that will support javascript.


Spiral Scripts
Written on Monday, 08 March 2010 11:19 by Spiral Scripts

Viewed 7983 times so far.
Like this? Tweet it to your followers!

Latest articles from Spiral Scripts

  • New Image Slideshow for Joomla 1.6/1.7/2.5 posted on Monday, 23 January 2012 17:27

    We are happy to announce the release of our new image slideshow module for Joomla…

  • Mod Panel Slider Documentation posted on Saturday, 21 January 2012 10:42

    Our Panel Slider Module displays your images in an attractive and unusual scrolling slideshow. Display…

  • New Tool for Joomla Developers posted on Saturday, 14 January 2012 11:51

    Self-Replicating Form Field for Joomla There are times as a Joomla extension developer when it…

  • Variable Form Field Documentation posted on Thursday, 12 January 2012 13:24

    The variable field form field can be used to generate self-replicating fields of most of…

  • Virtuemart 2.0 Released posted on Thursday, 05 January 2012 11:16

    On 19th December the much anticipated Virtuemart 2.0.0 was released. This is a great achievement…

Latest 'tweets' from Spiral Scripts

  • Some useful Joomla mailing lists http://t.co/lBNEoAcK Link Wednesday, 01 February 2012 12:31
  • New Image Slideshow for Joomla 1.6/1.7/2.5 http://t.co/z9Utb8z9 Link Monday, 23 January 2012 18:14
  • New Image Slideshow for Joomla 1.6/1.7/2.5: We are happy to announce the release of our new image slideshow modu... http://t.co/bWb5VBPh Link Monday, 23 January 2012 17:57
  • New Tool for Joomla Developers http://t.co/jm4F3OlS Link Saturday, 14 January 2012 13:51
  • New Tool for Joomla Developers: Self-Replicating Form Field for Joomla There are times as a Joomla extension dev... http://t.co/myKPsmLh Link Saturday, 14 January 2012 12:17
blog comments powered by Disqus

 
 
 

VirtueMart Featured Products Grid

Switch View

A module extension for the the Joomla CMS. It plays a random list of mp3s using the Flash media player.

£12.00
A Flash puzzle game for the Joomla! content management system. This would be suitable for a site aimed at children.

£12.00


This module can be used as a replacement for the Virtuemart featured products, top products, random products or recent products modules. It displays product images as a 3 Dimensional Flash slideshow.

£15.00


Buy both our Flash slideshow products for Virtuemart and save £5.

£25.00