js获取用户上传的文件&&判断用户设备

阅读 66

2022-03-19

  1. 直接写html标签
    iPhone 和Android通用
    选照片文件<input type="file" accept="image/*"/>
    打开摄像头<input type="file" capture /> 或者 <input type="file" capture accept="image/*"/>

  2. 判断安卓和苹果设备

const agent = navigator.userAgent;
const isAndroid = agent.indexOf('Android') > -1 || agent.indexOf('Linux') > -1; //android终端或者uc浏览器
const isiOS = !!agent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if(isAndroid){ //如果是安卓
  console.log("android");
}else if(isiOS) { //如果是ios
  console.log("apple");
}

精彩评论(0)

0 0 举报