发布于 2年前

ES6 如何确定设备是移动设备还是台式机/笔记本电脑?

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

// 事例
detectDeviceType(); // "Mobile" or "Desktop"
©2020 edoou.com   京ICP备16001874号-3