检查用户是否使用过网络摄像头? [英] Check if user has webcam or not using JavaScript only?
本文介绍了检查用户是否使用过网络摄像头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用JavaScript来确定用户是否拥有网络摄像头?我不想为此使用任何插件。
Is it possible to figure out whether a user has a webcam or not using only JavaScript? I don't want to use any plugin for this.
推荐答案
您可以使用新的HTML5 API检查它们是否为您提供允许使用网络摄像头。毕竟,如果他们拒绝许可,从代码的角度来看,他们也可能没有网络摄像头。
You can use a new HTML5 API to check if they give you permission to use the webcam. After all, if they deny permission, they might as well not have a webcam, from the code's perspective.
编辑:
navigator.getMedia = ( navigator.getUserMedia || // use the proper vendor prefix
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
navigator.getMedia({video: true}, function() {
// webcam is available
}, function() {
// webcam is not available
});
这篇关于检查用户是否使用过网络摄像头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文