Javascript 在用户授予权限后自动获取用户网络摄像头访问权限

Javascript 在用户授予权限后自动获取用户网络摄像头访问权限,javascript,html,html5-video,Javascript,Html,Html5 Video,我使用javascript创建了一个带有用户video div的页面。所以一旦用户给予许可,它会在网站的角落显示用户网络摄像头。因此,当我再次访问任何其他页面时,我需要请求用户许可。那么,有没有什么方法可以让用户在获得许可后自动访问网络摄像头呢 <div id="videoContainer"> <video autoplay="true" id="videoElement"></video>

我使用javascript创建了一个带有用户video div的页面。所以一旦用户给予许可,它会在网站的角落显示用户网络摄像头。因此,当我再次访问任何其他页面时,我需要请求用户许可。那么,有没有什么方法可以让用户在获得许可后自动访问网络摄像头呢

<div id="videoContainer">
    <video autoplay="true" id="videoElement"></video>
</div>
<script>
var video = document.querySelector("#videoElement");
var next_button = document.getElementById("button_1");


if (navigator.mediaDevices.getUserMedia) {
  navigator.mediaDevices.getUserMedia({ audio: true,video: true })
    .then(function (stream) {
      video.srcObject = stream;
      next_button.classList.remove("disabled");
      localStorage.setItem("camera_access", "granded");
    })
    .catch(function (error) {
        console.log(error);
        localStorage.setItem("camera_access", "declined");
    });
}
</script>

var video=document.querySelector(“#videoElement”);
var next_button=document.getElementById(“button_1”);
if(navigator.mediaDevices.getUserMedia){
navigator.mediaDevices.getUserMedia({audio:true,video:true})
.then(函数(流){
video.srcObject=流;
下一步按钮。类列表。删除(“禁用”);
setItem(“摄像头访问”、“granded”);
})
.catch(函数(错误){
console.log(错误);
setItem(“摄像头访问”、“拒绝”);
});
}
如果用户授予权限,我将在本地存储中保存我尝试的内容。但是使用这个值,我找不到访问网络摄像头的方法。请给我一些想法。 我想我可以使用ajax加载页面,但这将很困难,因为其他页面都是使用参数加载的。