function create_video_element(width,height)
{
	var video       = document.createElement('video');
	video.width = width;
	video.height    = height;
	video.autoplay  = true;
	video.controls  = false;
	document.body.appendChild(video);
	return video;
}

function isAvaliable()
{
	var hasUserMedia = navigator.webkitGetUserMedia ? true : false;
	return hasUserMedia;
}

function read_from_webcam(video)
{
	navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
		navigator.mozGetUserMedia || navigator.msGetUserMedia;
	window.URL = window.URL || window.webkitURL;

	navigator.getUserMedia({video: true}, function(stream){
	video.src   = window.URL.createObjectURL(stream);
	}, function(error){
		console.log("Failed to get a stream due to");//, error);
	});
}
<html lang="en-us" >
<head>
<script src="play_video.js"></script>

</head>
<body>

<script type="text/javascript">

if(isAvaliable())
{
	read_from_webcam(create_video_element(200,300));
}
else
{
	alert("camera not avaliable");
}

</script>

</body>

</html>