如何检查用户是否有网络摄像头


How can I check if user has a webcam or not?

我需要知道是否有办法知道用户的电脑上是否有使用javascript或php的网络摄像头。

if(confirm('Do you have a webcam?')) {
    //they said yes :-)
} else {
    //they said no :-(
}

有一个插件:

http://www.xarg.org/project/jquery-webcam-plugin/

if(webcam.getCameraList().length == 0){  
   alert('You don''t have a web camera');  
}
穆罕默特是对的。首先需要添加插件http://www.xarg.org/project/jquery-webcam-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() {}
        });

然后添加脚本,检查用户是否有网络摄像头。

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);

这个try-and-catch是有延迟启动的flash所需要的,所以你需要继续尝试,直到方法webcamer.getCameraList()存在为止。