加载移动CSS,如果用户是在Android [英] Load mobile CSS if user is on Android

查看:132
本文介绍了加载移动CSS,如果用户是在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.htaccess文件正在写一个聪明的cookie。如果我的页读取该cookie将会写入一个div。那么只有我的手机的CSS文件加载如果用户在iPhone或iPod。

我的问题是,我怎么可以编辑(下)这code加载移动CSS文件,如果用户在Android?

下面是我的页面和code:

 < META NAME =视口内容=WIDTH =设备宽度,用户可扩展= YES/>
<链接相对=样式类型=文/ CSS的href =CSS / mobile.css媒体=只屏(最大宽度:640px)/>
<脚本类型=文/ JavaScript的>
如果(window.screen.width> 640){文件撰写('< META NAME =视CONTENT =WIDTH = 980,用户可扩展= YES/>')}
如果((navigator.userAgent.match(/ iPhone / I))||(navigator.userAgent.match(/ iPod的/我))){文件撰写('<链接相对=样式类型=文/ CSS的href =CSS / mobile.css媒体=只屏(最大宽度:640px)/>')}
< / SCRIPT>
 

解决方案

您应该只能够添加

|| (navigator.userAgent.match(/安卓/ I))

第二个 if语句,所以

  IF((navigator.userAgent.match(/ iPhone / I))||
    (navigator.userAgent.match(/ iPod的/我))||
    (navigator.userAgent.match(/安卓/ I)))
 

My .htaccess file is writing a "smart" cookie. If my page reads this cookie it will write a div. Then my mobile CSS file loads only if the user's on an iPhone or iPod.

My question is, how can I edit this code (below) to load the mobile CSS file if the user's on an Android?

Here's my page and code:

<meta name="viewport" content="width=device-width, user-scalable=yes" /> 
<link rel="stylesheet" type="text/css" href="css/mobile.css" media="only screen and (max-width: 640px)" /> 
<script type="text/javascript">
if (window.screen.width > 640){document.write('<meta name="viewport" content="width=980, user-scalable=yes" />')}
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))){document.write('<link rel="stylesheet" type="text/css" href="css/mobile.css" media="only screen and (max-width: 640px)" />')}
</script>

解决方案

You should just be able to add

|| (navigator.userAgent.match(/Android/i))

to the second if statement, so

if( (navigator.userAgent.match(/iPhone/i)) || 
    (navigator.userAgent.match(/iPod/i)) || 
    (navigator.userAgent.match(/Android/i)) ) 

这篇关于加载移动CSS,如果用户是在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆