问题描述
我试图在Chrome浏览器中使用navigator.getUserMedia;然而,它不是在本地服务时请求权限(file:///whatever/index.html),而是在JSFiddle上()和其他网站。
有谁知道这个的原因?我需要以某种方式重置我的权限?
以下是我在本地使用的内容:
< HTML>
< head>< / head>
< body>
< button id =btn>开始< / button>
< script type =text / javascript>
/ *! jQuery v1.8.3 jquery.com | jquery.org/license * /
// JQuery去这里
< / script>
< script type =text / javascript>
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.getUserMedia;
$(function(){
$('#btn')。click(function(){
navigator.getUserMedia({audio:true},
function(){
alert('success');
},
function(err){
alert('fail:'+ JSON.stringify(err));
});});});
< / script>
< / body>
< / html>
Chrome屏蔽了 file:///
不报告安全性错误的URI(例如,)。您最好的选择是从本地网络服务器运行,如果您安装了Python,请尝试。
I'm attempting to play around with navigator.getUserMedia in Chrome; however, it is not requesting permission when served locally (file:///whatever/index.html), but does on JSFiddle ( http://jsfiddle.net/EBsvq/ ) and other sites.
Does anyone know the reason for this? Do I need to somehow reset my permissions?
Here is what I am using locally:
<html>
<head></head>
<body>
<button id="btn">Start</button>
<script type="text/javascript">
/*! jQuery v1.8.3 jquery.com | jquery.org/license */
//JQuery goes here
</script>
<script type="text/javascript">
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.getUserMedia;
$(function(){
$('#btn').click(function(){
navigator.getUserMedia({audio: true},
function(){
alert('success');
},
function (err) {
alert('fail: ' + JSON.stringify(err));
}); }); });
</script>
</body>
</html>
Chrome blocks a lot of stuff on file:///
URIs without reporting a security error (eg. Geolocation). Your best option is to run from a local webserver, if you have Python installed try SimpleHTTPServer.
这篇关于Chrome getUserMedia本地不请求权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!