Here is my code:
<script type="text/javascript">
if (navigator.userAgent.indexOf('BlackBerry')!= -1){
document.write('<link rel="stylesheet" href="/m/css/mobile.css" type="text/css" />');
} else if (navigator.userAgent.indexOf('iPhone')!= -1) {
document.write('<link rel="stylesheet" href="/m/css/smartmobile.css" type="text/css" />');
}else if (navigator.userAgent.indexOf('Android')!= -1) {
document.write('<link rel="stylesheet" href="/m/css/smartmobile.css" type="text/css" />');
} else if (navigator.userAgent.indexOf('Windows XP')!= -1) {
document.write('<link rel="stylesheet" href="/m/css/smartmobile.css" type="text/css" />');
}
else{
document.write('<link rel="stylesheet" href="/m/css/mobile.css" type="text/css" />');
}
</script>
Clearly my Windows XP one is wrong. Anyone know what I need to replace it with so that the /css/mobile.css only shows up on phones other than the iPhone and Android devices.
Whether I need to add Linux and Windows or all the popular browsers instead of OS
you need a user-agent for a browser, not an operating system, but here you go:
‘Windows NT’ for windows
and:
‘MSIE’ explorer
‘Gecko’ for firefox (and browsers with gecko engine)
but seriously, you shouldn’t need to know what os it is, but what browser