[英]Joomla 2.5 - Add Custom CSS for iPad
I want to load a css file when viewing my joomla website on iPad. 在iPad上查看我的joomla网站时,我想加载一个CSS文件。
The joomla version I am using is 2.5. 我正在使用的joomla版本是2.5。
I currently have style-sheets set for browsers eg Internet Explorer and Firefox but not sure how to tell the website to load a css file specifically for a device eg iPad. 我目前为浏览器(例如Internet Explorer和Firefox)设置了样式表,但不确定如何告诉网站加载专门用于设备(例如iPad)的CSS文件。
Any help would be appreciated. 任何帮助,将不胜感激。
@isher's answer is a good method, however to import the CSS file, I would do it like so, using Joomla coding standards: @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" );
}
?>
Something like this should do it: 这样的事情应该做到:
<?php
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
if $isiPad;
echo "<link href='ipad-styles.css' rel='stylesheet' type='text/css'>";
?>
Or you can use this script and add to your template or custom module (assigned to all page): 或者,您可以使用此脚本并将其添加到模板或自定义模块(分配给所有页面)中:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.