最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Camera capture using Html5 input tag - Stack Overflow

programmeradmin4浏览0评论

I am using the below line of code in order to invoke camera from my web application.

<input type="file" id="capture" accept="image/*; capture=camera" style="visibility:hidden;">

Using this, I am able to get the pop up with options of "Choose existing photo" and "Take Picture", when the application is opened in iOS6. But I want to open up camera capture directly rather then getting this pop up and then select "Take Picture" option.

Thanks in advance.

I am using the below line of code in order to invoke camera from my web application.

<input type="file" id="capture" accept="image/*; capture=camera" style="visibility:hidden;">

Using this, I am able to get the pop up with options of "Choose existing photo" and "Take Picture", when the application is opened in iOS6. But I want to open up camera capture directly rather then getting this pop up and then select "Take Picture" option.

Thanks in advance.

Share Improve this question edited Mar 22, 2013 at 8:36 Atanas Korchev 30.7k8 gold badges61 silver badges94 bronze badges asked Mar 22, 2013 at 5:28 Kiara_2013Kiara_2013 1711 gold badge1 silver badge3 bronze badges 5
  • can you post the rest of the code where you get to camera capture etc. – btevfik Commented Mar 22, 2013 at 5:34
  • code used for camera capture is :<div class="clsAttachViewLabel" align="middle"> <label class="clsCaptureLabel" data-click="onClickTake" >Take a Photo</label> </div> <input type="file" id="capture" accept="image/*; capture=camera" style="visibility:hidden;"> In JS File : function onClickTake() { $("#capture").click(); } – Kiara_2013 Commented Mar 22, 2013 at 11:55
  • Is there any way by which I can modify even the options which appear in pop up in iOS6 For example:options we get in pop up are "Choose Existing","Take Photo or Video" and "Cancel".If I want only "Take Photo" option,how can I display that alone in pop up – Kiara_2013 Commented Mar 22, 2013 at 11:59
  • Those buttons are part of iOS and are immutable. There is currently nothing you can do to change/bypass this menu from a web app. – srquinn Commented Apr 14, 2013 at 23:01
  • @Kiara_2013 any chance of marking an answer? Thanks! :) – Ian Grainger Commented Mar 24, 2015 at 9:40
Add a comment  | 

3 Answers 3

Reset to default 9
<input type="file" name="file" accept="image/*" capture="camera" />

Works in Chrome on Android (at least).

I'm afraid this is not possible as per the specification for security/privacy reasons:

The user agent SHOULD NOT enable any device for media capture, such as a microphone or camera, until a user interaction giving implicit consent is completed.

http://www.w3.org/TR/capture-api/#security

An alternative is to use getUserMedia. This still shows a dialog requesting user permission but in some browsers the user can choose to hide it after granting access to a domain.

What browser are you using on Android? This page indicates that it doesn't work on Chrome but should work on the Android browser and on iOS Safari. It doesn't specifically mention Chrome for Android. I tested the tag with the Chrome browser on my LG G6 phone and it didn't work. I wasn't able to test Android browser--it seems to be missing on my phone.

https://caniuse.com/#feat=html-media-capture

发布评论

评论列表(0)

  1. 暂无评论