HTML5页面如何在手机端浏览器调用相机、相册功能

开发微信端浏览器访问的HTML5的页面,页面中有一个<input id="input" type="file"/>标签,iOS直接就支持吊起相机拍照或是相册选择,

但android中不支持吊起相机拍照,只能吊起相册选择,网上的帖子说是因为android屏蔽了文件上传功能还是怎么的,没看明白。

此篇博文记录如何解决这一问题,使得android也可以直接吊起相机拍照。

在查资料的之后,总结了一下用input调用相机和相册功能的方法,之前没有深入了解过,现在整理一下:

不需要特殊环境,使用input标签 type值为file,可以调用系统默认的照相机、相册、摄像机、录音功能。先上代码:

复制代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>HTML5页面如何在手机端浏览器调用相机、相册功能</title>
  </head>
  <body> 
    <div>
      <input type="file" accept="image/*" capture="camera">
      <input type="file" accept="video/*" capture="camcorder">
      <input type="file" accept="audio/*" capture="microphone">
    </div>
  </body>
</html>

复制代码

accept表示打开的系统文件目录;
capture表示的是系统所捕获的默认设备,camera:照相机;camcorder:摄像机;microphone:录音。

 如果不加上capture,则只会显示相应的,例如上述三种依次是:拍照或图库,录像或图库,录像或拍照或图库,加上capture之后不会调用图库。

 其中还有一个属性multiple,支持多选,当支持多选时,multiple优先级高于capture,

所以只用写成:<input type="file" accept="image/*" multiple>就可以,可以在手机上测试一下。

原文地址:https://blog.csdn.net/Zhihua_W/article/details/78125622

猜你喜欢

转载自blog.csdn.net/hsany330/article/details/109445262