0

I have a site that I want to behave slightly differently on a computer than on a mobile device (phone or tablet) and I want a function that I can call to figure out what type of device I'm on. Is there like window.getDevice or document.getDevice or something like that?

  • 1
    What exactly is the behavior that will differ between mobile and desktop? That will inform how to answer this question. – ldtcoop Jul 08 '19 at 22:17
  • Take a look at this SO answer: https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device . There are shown some techniques per user-agent and a hacky method that uses a portion of CSS (I really like that one). – Torsten Barthel Jul 08 '19 at 22:20
  • 2
    Possible duplicate of [What is the best way to detect a mobile device?](https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device) – Jonathan Jul 09 '19 at 00:03

1 Answers1

0

I think that there isn't a way to get the device name.

You can use:

window.navigator.userAgent to get info about platform in use and browser.

and

window.screen to get an object with available width and available height that tell you the real width and height of device in use.