I need to know if there's a way to know if the user has a webcam on his computer using javascript or maybe php.
There is a plugin:
if(webcam.getCameraList().length == 0){
alert('You don\'t have a web camera');
}
if(confirm('Do you have a webcam?')) {
//they said yes :-)
} else {
//they said no :-(
}
Muhammet was right. First need to add the plugin http://www.xarg.org/project/jquery-webcam-plugin/ Then you'll need to start the plugin:
$("#camera").webcam({
width: 320,
height: 240,
mode: "callback",
swffile: "/lorran/jscam_canvas_only.swf",
onTick: function() {},
onSave: function() {},
onCapture: function() {},
debug: function() {},
onLoad: function() {}
});
Then you add the script that check if user has a webcam.
var test;
test = function(){
var tester = false;
try{
if(webcam.getCameraList().length == 0){
alert('You dont have a camera');
return;
}else{
alert("cam");
return;
}
tester = true;
}catch(e){
tester = false;
setTimeout(test,1000);
}
}
setTimeout(test,1000);
This try and catch is needed for the flash that have a delay to start, so you need to keep trying till the method webcam.getCameraList() exist.
来源:https://stackoverflow.com/questions/20641213/how-can-i-check-if-user-has-a-webcam-or-not