0
点赞
收藏
分享

微信扫一扫

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

小云晓云 2022-03-19 阅读 65
前端
  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 条评论