input[type='file']安卓手机微信端无法调用摄像头问题

  • 使用input type=file标签进行文件上传时,在安卓手机中的微信浏览器中不能调起相机,但是在苹果手机中的微信浏览器中可以调用相机。解决办法:
type="file" name="upload" accept="image/png,image/jpeg,image/gif" capture="camera">
accept属性:调用相册功能(ios也可以直接调用相机)
capture属性:可以保证安卓手机调用相机功能。
注意:如果加了这条属性,会导致ios手机直接调用相机而无法选择相册中的文件
解决方法:
判断设备类型,动态添加capture属性(我使用Zepto判断):
var plateform = Zepto.device.os;
if(plateform == "android"){
 $("selector").find("input[type='file']").attr("capture","camera");
}else if(plateform=="ios"){         
  $("selector").find("input[type='file']").removeAttr("capture");
}

备注:accept和capture两个属性都需要

你可能感兴趣的:(h5-app)