使用navigator.userAgent来检测网站运行在哪种平台设备上。

 

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

console.log(detectDeviceType());

 

posted @ 2023-01-29 09:00  磊~~  阅读(21)  评论(0编辑  收藏  举报