2012-05-22 22 views
2
<link media="only screen and (min-device-width : 320px) and (max-device-width : 480px)" href="smartphone.css" type= "text/css" rel="stylesheet" /> 
<link media="only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5)" href="iphone.css" type= "text/css" rel="stylesheet" /> 

我在做對吧?或者有更好的方式來做到這一點?Html加載CSS如果檢測到手機

回答

0

像科爾提到的,你可以檢查的userAgent。這是一些JavaScript,你可以用它來檢測是否的userAgent是一個iPhone。 (Source

<script language=javascript> 
<!-- 
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { 
//Change the css 
} 
--> 
</script> 
0

你可以看一下TE用戶代理,並加載適當一個用PHP。使用限制但你320-480。黑莓就像是240×320,我認爲(至少9XXX系列)