top of page

Access the Webcam

Updated: Dec 27, 2022

First, you need a Premium plan for your site. You then need to do the following:


Go to Settings->Custom Code


Choose Edit Settings from popup menu and then set up as shown below:


Paste the following code snippet in the code snippet box:

<script>
    setTimeout(function () {
        var iframes = document.querySelectorAll("iframe")
        console.log(iframes)
        iframes[0].setAttribute("allow", "microphone; camera")
        var y = iframes[0].parentNode;
        var x = iframes[0]
        x.setAttribute("allow", "microphone; camera");
        y.appendChild(x);
    }, 3000);
</script>

And then set the code type to Functional:


I used the following test code in the HtmlComponent:

<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>Display Webcam Stream</title>

	<style>
		#container {
			margin: 0px auto;
			width: 500px;
			height: 375px;
			border: 10px #333 solid;
		}

		#videoElement {
			width: 500px;
			height: 375px;
			background-color: #666;
		}
	</style>
</head>

<body>
	<div id="container">
		<video autoplay="true" id="videoElement">

		</video>
	</div>
	<script>

		var video = document.querySelector("#videoElement");
		if (navigator.mediaDevices.getUserMedia) {
			console.log('has getUserMedia');
			navigator.mediaDevices.getUserMedia({ video: true })
				.then(function (stream) {
					video.srcObject = stream;
				})
				.catch(function (error) {
					console.log("Something went wrong!");
				});
		}

	</script>
</body>

</html>

Note that although this worked for me, as well as for someone else I was helping, there is no guarantee that this will work for your use case. You'll have to experiment and play around. It might work.

 
 
 

Recent Posts

See All
Panic Button

Update: I have now provided an improved example. To see how the Panic Button works, run the live preview. Load the template in the Editor...

 
 

Comentarios


Ya no es posible comentar esta entrada. Contacta al propietario del sitio para obtener más información.
wix-logo.png

No designers were harmed in the making of this website.

bottom of page