How to test if the browser support <input capture />

廉价感情. 提交于 2020-01-15 10:23:18

问题


How could I test if the current browser support the feature of mobile browsers to use the device camera to take a picture?

https://addpipe.com/html-media-capture-demo/

Capture is basically ignored in all desktop browsers: https://caniuse.com/#feat=html-media-capture

How could I detect if I can use capture (and that it won't show an open file dialog, but will actually open the picture application)?


回答1:


You can create an input element in JS and test for the capture property. It will be undefined if unsupported.

var el = document.createElement('input')
var supported = el.capture != undefined

console.log('capture supported: '+supported)

Here's what it looks like in the iOS simulator




回答2:


You can use the following function:

function supported(attribute) {
   var i = document.createElement('input');
   i.setAttribute(attribute, true);
   return !!i[attribute];
}

And you can call it, like supported('capture'), or if you want to test for the accept attribute supported('accept')

Source: http://anssiko.github.io/html-media-capture/



来源:https://stackoverflow.com/questions/51273828/how-to-test-if-the-browser-support-input-capture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!