Js如何确定设备是移动端还是桌面端

const detectDeviceType = () =>
  /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
    ? 'Mobile'
    : 'Desktop';
detectDeviceType(); // "Mobile" or "Desktop"

判断ios

/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent);

navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
posted @ 2020-09-15 11:18  weekai  阅读(184)  评论(0编辑  收藏  举报