Search This Blog

Jul 3, 2012

How to check browser platform in javascript

Are you planning to set a different html page to your users depending on the platform that they were using? If yes, then, this snippet might be useful for you in order to implement that functionality.

All you need to do is to know use and invoke the browser navigator object. It contains all the information about the browser that your users using. 

You can do the following javascript code to get the navigator platform.

<script type="text/javascript">

   var browser_platform = navigator.platform; 

   if(browser_platform == "iPhone"){
     //code for your iphone users 

The navigator.platform will return for which platform the browser is compiled. Ex: (iPhone, iPad, Android)

Other properties of Navigator object are: 

a.  appCodeName  -  return the code name of the browser.
b. appName - name of the browser
c. appVersion - return the version information of the browser.
d. cookieEnabled  - check if cookies are enable in your browser
e. userAgent   - return the user-agent header sent by the browser.

Hope you find it useful.