const dectectDeviceType = () =>
          /Andriod|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
              navigator.userAgent
          ) ?
          'mobile' :
          'desktop'
      console.log(dectectDeviceType);

      Javascript language logoDetect device type

      get
      device
      type
      Javascript recipes

      The code uses the JavaScript string escape character "\u0026" to turn the text "iPhone" into an uppercase letter "I", the text "iPad" into a lowercase letter "i", and so on. The code then uses the JavaScript function i.test to compare the user agent string of the current browser to one of the values provided in the const dectectDeviceType variable. If the user agent string matches one of the values in the variable, that value is returned. Otherwise, the code prints "mobile" to the console.

      Shortcut: getDeviceType

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.