Frontend/JavaScript
How to Tell PC from Mobile in A Responsive APP
Jin-Co
2023. 3. 23. 17:35
반응형
A responsive application uses the same URL for both PC and mobile view so traditional way of differentiating between the PC and mobile using URL path cannot be used to implement desired features. In this writing I will show you a trick to go around this in a berry simple way
Implementation
The code we will use looks like below
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
When you put the code in the console and run it, you will see that it only returns 'true' when the device mode is set to mobile


So you can use this as a condition to implement features that depends of the type of a device!
728x90
반응형