我正在尝试在Chrome中使用navigator.getUserMedia;然而,当它在本地提供服务时(file:///whatever/index.html),,但在JSFiddle ( http://jsfiddle.net/EBsvq/ )和其他网站上却可以),它不会请求许可。
有人知道这是什么原因吗?我需要以某种方式重置我的权限吗?
以下是我在本地使用的内容:
<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>
发布于 2012-12-05 22:41:57
Chrome在没有报告安全错误的情况下阻止了file:///
URI上的许多东西(例如。Geolocation)。您最好的选择是从本地try服务器运行,如果您安装了Python,请尝试SimpleHTTPServer。
发布于 2014-02-26 07:16:36
您可以在打开chrome时从命令行使用--allow-file-access-from-files
标志,以便能够从本地文件系统使用getUserMedia
。
发布于 2014-08-23 07:20:18
在OS中如何使用命令行arg并不是件容易的事,通常看起来是这样的
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --allow-file-access-from-files
如果你像我一样是个怪胎,把你的应用程序放在~/Applications
中,那么它将是
"/Users/yougohere/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --allow-file-access-from-files
如果这两个都不起作用,那么在你的Chrome地址栏中输入chrome://version
,它会告诉你应该使用什么“命令行”调用。只需添加--allow-file-access-from-files
即可。
https://stackoverflow.com/questions/13723699
复制相似问题