Php Joomla 2.5-为iPad添加自定义CSS
我想在iPad上查看joomla网站时加载css文件 我使用的joomla版本是2.5 我目前已经为浏览器(如Internet Explorer和Firefox)设置了样式表,但不知道如何告诉网站专门为设备(如iPad)加载css文件Php Joomla 2.5-为iPad添加自定义CSS,php,html,css,joomla,joomla2.5,Php,Html,Css,Joomla,Joomla2.5,我想在iPad上查看joomla网站时加载css文件 我使用的joomla版本是2.5 我目前已经为浏览器(如Internet Explorer和Firefox)设置了样式表,但不知道如何告诉网站专门为设备(如iPad)加载css文件 任何帮助都将不胜感激 像这样的东西应该可以做到: <?php $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad'); if $isiPad; echo "<link hre
任何帮助都将不胜感激 像这样的东西应该可以做到:
<?php
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
if $isiPad;
echo "<link href='ipad-styles.css' rel='stylesheet' type='text/css'>";
?>
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" );
}
?>
或者您可以使用此脚本并添加到模板或自定义模块(分配给所有页面):
jQuery(函数($){
var userAgent=navigator.userAgent.toLowerCase();
var regex=new RegExp('ipad','i');
if(userAgent.match(regex)){
$('').appendTo($('head');
}});
<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>