2011-06-23 28 views
4

我的.htaccess文件正在寫入一個「智能」cookie。如果我的頁面讀取這個cookie,它會寫入一個div。然後,我的手機CSS文件僅在用戶使用iPhone或iPod時才加載。如果用戶在Android上加載手機CSS

我的問題是,如果用戶在Android上,我該如何編輯此代碼(以下)以加載移動CSS文件?

這裏是我的page和代碼:

<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> 

回答

5

你應該只能夠

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

添加到第二if statement,所以

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

這個片段將做到這一點:

navigator.userAgent.match(/android/) 
相關問題