I am trying to use Webcam.js to capture image in my MVC project. But at the initial level I have an issue "Could not locate DOM element to attach to."
I have attached script
<style>
.Camera {
width: 320px;
height: 240px;
border: 1px solid black;
}
</style>
<script type="text/javascript" src="~/Scripts/webcam.min.js"></script>
<script language="JavaScript">
Webcam.set({
width: 320,
height: 240,
image_format: 'jpeg',
jpeg_quality: 90
});
Webcam.attach('#Camera');
</script>
In View
<div>
<div id="Camera" class="Camera"> </div>
<br>
<input type="button" id="takeshot" value="Capture" onClick="take_snapshot()" />
</div>
What is the possible cause?
place your javascript functions beneath the tag/element id:camera and id:takeshot
Try this: Delete the class Camera, happened with me but after deleting the class and just keeping the "id" it worked.
camera = document.getElementById("camera");
Webcam.attach(camera);
Webcam.set({ width:350, height:300, image_format: 'png', png_quality:90 });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.