본문 바로가기

Frontend/JavaScript

How to Tell PC from Mobile in A Responsive APP

반응형

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

PC
Mobile

So you can use this as a condition to implement features that depends of the type of a device!
 

728x90
반응형

'Frontend > JavaScript' 카테고리의 다른 글

Data Request  (1) 2023.03.24
Day / Night Mode with JavaScript  (1) 2023.03.24
Modal  (0) 2023.03.14
Infinite Scrolling  (0) 2023.03.14
JS Component - Expanding Search Bar  (1) 2023.03.08