Javascript 如果用户在Android上,则加载移动CSS
我的.htaccess文件正在编写“智能”cookie。如果我的页面读取此cookie,它将写入一个div。然后,只有当用户在iPhone或iPod上时,才会加载我的移动CSS文件 我的问题是,如果用户在安卓系统上,我如何编辑下面的代码来加载移动CSS文件 这是我的密码:Javascript 如果用户在Android上,则加载移动CSS,javascript,android,css,mobile,viewport,Javascript,Android,Css,Mobile,Viewport,我的.htaccess文件正在编写“智能”cookie。如果我的页面读取此cookie,它将写入一个div。然后,只有当用户在iPhone或iPod上时,才会加载我的移动CSS文件 我的问题是,如果用户在安卓系统上,我如何编辑下面的代码来加载移动CSS文件 这是我的密码: <meta name="viewport" content="width=device-width, user-scalable=yes" /> <link rel="stylesheet" type="t
<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>
如果(window.screen.width>640){document.write(“”)}
if((navigator.userAgent.match(/iPhone/i))| |(navigator.userAgent.match(/iPod/i)){document.write(“”)}
您应该可以添加
||(navigator.userAgent.match(/Android/i))
到第二个if语句
,所以
if( (navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i)) ||
(navigator.userAgent.match(/Android/i)) )
给你:)
这段代码可以:
navigator.userAgent.match(/android/)