2013-01-13 98 views
0

我想在iPad上查看我的joomla網站時加載CSS文件。Joomla 2.5 - 爲iPad添加自定義CSS

我使用的joomla版本是2.5。

我目前已爲瀏覽器設置了樣式表, Internet Explorer和Firefox,但不知道如何告訴網站專門爲設備加載css文件,例如iPad兼容。

任何幫助,將不勝感激。

回答

0

像這樣的東西應該這樣做:

<?php 
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad'); 

if $isiPad;  
    echo "<link href='ipad-styles.css' rel='stylesheet' type='text/css'>"; 
?> 
1

@ isher的回答是一個很好的方法,但是導入CSS文件,我會做它像這樣,使用Joomla編碼標準:

<?php 
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad'); 

if ($isiPad){  
    $doc = JFactory::getDocument(); //only include if line doesn't already exist 
    $doc->addStyleSheet (JURI::root() . "template/template-name/ipad-styles.css"); 
} 
?> 
0

或者您可以使用此腳本並添加到您的模板或自定義模塊(分配給所有頁面):

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
<script type="text/javascript"> 
jQuery(function($){ 
var userAgent = navigator.userAgent.toLowerCase(); 
var regex = new RegExp('ipad',"i"); 
if(userAgent.match(regex)){ 
    $('<link href="css/ipad.css" rel="stylesheet" type="text/css"/>').appendTo($('head')); 
}}); 
</script> 
相關問題