微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html5 – Chrome getUserMedia本地不要求许可

我试图在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>

解决方法

Chrome阻止了很多文件:/// URI,而不报告安全错误(例如 Geolocation)。您最好的选择是从本地的Web服务器运行,如果您安装了Python SimpleHTTPServer

原文地址:https://www.jb51.cc/html5/168971.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。