Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check device type in javascript

const detectDeviceType = () =>
   /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
      navigator.userAgent
   )
      ? 'Mobile'
      : /(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(
           navigator.userAgent
        )
      ? 'Tablet'
      : 'Desktop';
console.log(detectDeviceType());
Comment

get device type using javascript

const getDeviceType = () => {
  const ua = navigator.userAgent;
  if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) {
    return "tablet";
  }
  if (
    /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(
      ua
    )
  ) {
    return "mobile";
  }
  return "desktop";
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery doc ready 
Javascript :: chartjs remove legend 
Javascript :: hidden jquery 
Javascript :: how to convert string to int a array in javascript 
Javascript :: Jquery SEND TO START OF ARRAY 
Javascript :: package.json: License should be a valid SPDX license expression 
Javascript :: setup ejs views directory in express 
Javascript :: require statement not part of import statement javascript 
Javascript :: chart.js hide bar title 
Javascript :: yup only characters regex validation react 
Javascript :: javascript regex number only 
Javascript :: discord.js create unexipable invite 
Javascript :: javascript open link with button 
Javascript :: jquery on event snippet 
Javascript :: js how to check typeof boolean 
Javascript :: javascript string to integer 
Javascript :: Ajax Form All Data Send 
Javascript :: change style of class divs jquery 
Javascript :: default ordering false in datatable 
Javascript :: brand icons in next js 
Javascript :: javascript remove last character from string 
Javascript :: how to set view engine in express 
Javascript :: js wrap an element 
Javascript :: nodejs to exe 
Javascript :: login discord token 
Javascript :: local storage check max size 
Javascript :: javascript loop through string 
Javascript :: sort ip address javascript 
Javascript :: createdAt 
Javascript :: laravel variable in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =