check if mobile js code example

Example 1: js if mobile browser

// credit to Timothy Huang for this regex test: 
// https://dev.to/timhuang/a-simple-way-to-detect-if-browser-is-on-a-mobile-device-with-javascript-44j3
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
  return true
}
else{
  return false
}

Example 2: detect mobile javascript

/* npm i tappify */
import Tappify from "tappify";

/* Only works in react.js */
function myComponent() {
  return <>
    
      Client is using finger *tap tap*
    
 
    
      Client is using mouse cursor *click click*
    
  
}
//more info: https://github.com/asplunds/tappify

Tags:

Misc Example