0

I want to know if there is anyway for the javascript file to detect which device is it so that it can run the specified js file?

For example, I have two js file - a.js and b.js, and I want that if it's a iOS device, so the a.js is executed, and if they're other devices (like pc and androids) - so b.js is executed.

Ethan
  • 881
  • 8
  • 14
  • 26
  • Can [this](https://stackoverflow.com/questions/21741841/detecting-ios-android-operating-system) help? – David R Jun 20 '22 at 16:10
  • check if this device, is PC or mobile is easy with `navigator.userAgentData.mobile === 'true'` but checking if is android or iphone needs more code, I suggest using @DavidR comment link! maybe helps... for example in my case is logging `false` and if you use the same `userAgentData` with `.platform` you can get also what platform the user is (for example in my case "windows" – Laaouatni Anas Jun 20 '22 at 16:11
  • Why do you need to have different scripts depending on the device? Generally you want to do feature checking instead of checking for the device type. Checking for the device type is error prone. What if your assumption about what the device is capable of changes with an update of the device? – t.niese Jun 21 '22 at 21:17

0 Answers0