如何测试浏览器是否支持<input capture =“” />

时间:2018-07-10 21:00:49

标签: javascript html5 browser

如何测试当前的浏览器是否支持移动浏览器的功能以使用设备相机拍照?

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

在所有台式机浏览器中,捕获基本上都被忽略:https://caniuse.com/#feat=html-media-capture

如何检测我是否可以使用捕获(捕获不会显示打开的文件对话框,但实际上会打开图片应用程序)?

2 个答案:

答案 0 :(得分:1)

您可以在JS中创建一个input元素,并测试capture属性。如果不受支持,它将是不确定的。

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

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

这就是iOS模拟器中的样子

enter image description here

答案 1 :(得分:1)

您可以使用以下功能:

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

您可以调用它,例如supported('capture'),或者如果您想测试accept属性supported('accept')

  

来源:http://anssiko.github.io/html-media-capture/

相关问题