Compago

...free knowledge

 
  • Increase font size
  • Default font size
  • Decrease font size
Home Manuali Programmazione Using the Browser Detection in Joomla

Using the Browser Detection in Joomla

E-mail Stampa PDF

Using Joomla it is necessary to add some extra coding that will deal with a particular web browsers, so you need a browser detection, that it's handled through the JBrowser class. 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();

By this object instance you can then find information about the web browser being used through examing the properties of this object:

  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.

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.
If you need che the complete documentation on the Joomla website.

Example:

jimport('joomla.environment.browser');
$document =& JFactory::getDocument();
$browser = &JBrowser::getInstance();
$browserType = $browser->getBrowser();
$browserVersion = $browser->getMajor();
if(($browserType == 'msie') && ($browserVersion < 7)) {
$document->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' );
}

The available "quirks" list is:

  • avoid_popup_windows
  • break_disposition_header
  • break_disposition_filename
  • broken_multipart_form
  • cache_same_url
  • cache_ssl_downloads
  • double_linebreak_textarea
  • empty_file_input_value
  • must_cache_forms
  • no_filename_spaces
  • no_hidden_overflow_tables
  • ow_gui_1.3
  • png_transparency
  • scrollbar_in_way
  • scroll_tds
  • windowed_controls

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'')

The function hasFeature('javascript') report only if the browser supports javascript but does not take account of the fact that users can choose to disable scripting on the browser.

The "features" list is:

  • html
  • hdml
  • wml
  • images
  • iframes
  • frames
  • tables
  • java
  • javascript
  • dom
  • utf
  • rte
  • homepage
  • accesskey
  • optgroup
  • xmlhttpreq
  • cite
  • xhtml+xml
  • mathml
  • svg
Ultimo aggiornamento ( Sabato 12 Maggio 2012 08:40 )  
Loading

Login




Chiudi