know if a mobile open the website js 1

know if a mobile open the website js

// 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
}

Here is what the above code is Doing:
1. It’s checking the user agent string of the browser.
2. If the user agent string contains any of the following:
– Android
– webOS
– iPhone
– iPad
– iPod
– BlackBerry
– IEMobile
– Opera Mini
3. Then it returns true.
4. Otherwise, it returns false.

Similar Posts