Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get the device which is used by the user

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 228
    Comment on it

    Sometimes we have to write down the different scripts for different devices. Now a days most used devices are mobiles/tablets. If you want to get the device type which user is using then you need to simply add this script in your code and call this function when needed. We are using navigator.userAgent which is useful to get the user-agent header value sent by the browser to web server. Please have a look.


    <script>
    function isMobileDevice(){
     var isMobile = {
      Android: function() {
          return navigator.userAgent.match(/Android/i) && navigator.userAgent.match(/mobile|Mobile/i);
      },
      BlackBerry: function() {
          return navigator.userAgent.match(/BlackBerry/i)|| navigator.userAgent.match(/BB10; Touch/);
      },
      iOS: function() {
          return navigator.userAgent.match(/iPhone|iPod/i);
      },
      Opera: function() {
          return navigator.userAgent.match(/Opera Mini/i);
      },
      Windows: function() {
          return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/webOS/i) ;
      },
      any: function() {
          return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
      }
    };      
     return isMobile.any()
    }
    </script>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: