如果用户在 Android 上,则加载移动 CSS [英] Load mobile CSS if user is on Android
本文介绍了如果用户在 Android 上,则加载移动 CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 .htaccess 文件正在编写一个智能"cookie.如果我的页面读取此 cookie,它将写入一个 div.然后我的移动 CSS 文件仅在用户使用 iPhone 或 iPod 时加载.
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.
我的问题是,如果用户使用的是 Android,我该如何编辑此代码(如下)以加载移动 CSS 文件?
My question is, how can I edit this code (below) to load the mobile CSS file if the user's on an Android?
这是我的页面和代码:
<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>
推荐答案
您应该能够添加
<代码>||(navigator.userAgent.match(/Android/i))
到第二个if语句
,所以
if( (navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i)) ||
(navigator.userAgent.match(/Android/i)) )
这篇关于如果用户在 Android 上,则加载移动 CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文