Need to detect mobile browser and load mobile.css file for Joomla template with PHP -


i need detect if using mobile browser (media queries aren't enough in situation) via php , load mobile.css file override few lines of css due lack of proper support code i'm using. i'm building joomla template, need dynamically generate path css file. so, doing right? example:

<?php $iphone = strpos($_server['http_user_agent'],"iphone"); $android = strpos($_server['http_user_agent'],"android"); $palmpre = strpos($_server['http_user_agent'],"webos"); $berry = strpos($_server['http_user_agent'],"blackberry"); $ipod = strpos($_server['http_user_agent'],"ipod");  if ($iphone || $android || $palmpre || $ipod || $berry == true)  {  echo "<link rel="stylesheet" href="$this->baseurl/templates/$this->template/css/mobile.css" type="text/css">"; } ?> 

in joomla there's mobile detection built in.

if using joomla 3.0, may use:

<?php $templateurl = $this->baseurl . '/templates/' . $this->template; $doc         = jfactory::getdocument(); $appweb      = new japplicationweb; // new jwebclient; (in joomla 2.5)  if ($appweb->client->mobile) {     $doc->addstylesheet($templateurl . '/css/mobile.css'); } ?> 

in joomla 2.5 or lower you'd use $appweb = new jwebclient

in joomla 3.4 you'll use if (jfactory::getapplication()->client->mobile)

i didn't find documentation page, may inspect source code

by way, check out responsive frameworks. takes time learn it's worth to.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -