Rya*_*yan 4 javascript css mobile android viewport
我的.htaccess文件正在编写一个"智能"cookie.如果我的页面读取此cookie,它将写一个div.然后我的移动CSS文件只在用户在iPhone或iPod上加载.
我的问题是,如果用户在Android上,如何编辑此代码(如下所示)以加载移动CSS文件?
这是我的页面和代码:
<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>
Run Code Online (Sandbox Code Playgroud)
你应该只能添加
|| (navigator.userAgent.match(/Android/i))
到了第二个if statement,所以
if( (navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i)) ||
(navigator.userAgent.match(/Android/i)) )
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7666 次 |
| 最近记录: |