Thursday, April 5, 2018

JS: How to detect mobile devices

This script detects windows mobile devices. For additional devices search for userAgent variables


  // Used to detect whether the users browser is an mobile browser
  function isWinMobile() {
      ///Detecting whether the browser is a windows mobile browser or desktop browser
      ///A boolean value indicating whether the browser is a windows mobile browser or not
      // other devices/os = ['iphone','ipad','android','blackberry','nokia','opera mini','windows mobile','windows phone','iemobile','tablet','mobi'];

      if((navigator.userAgent.match(/Windows Phone/i))||(navigator.userAgent.match(/iemobile/i))){
        return true;
      }

  }

  var isWinMobile = isWinMobile();
  if(isWinMobile==true){
    //this is windows mobile phone
  }

No comments:

Post a Comment