Tutorial :Windows User Agent [duplicate]



Question:

This question already has an answer here:

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


Solution:1

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


Solution:2

Maybe this link can help you: Browser Detection

But filter by OS is not a good choice. You must make this filter by browser because an OS can have all the browsers, and the website should look the same on all the browsers no matter what OS is being used.

The script from this link covers the recent browsers being used today, so it should fit what you want. =)


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »