reCAPTCHA访问属性的权限被拒绝

时间:2017-02-20 20:58:09

标签: javascript recaptcha

当我点击框确认我不是机器人时,蓝色微调器开始旋转但从未停止。最终在浏览器控制台中出现错误“错误:拒绝访问属性的权限”,然后是(看似)随机的10-15字符串,例如, “rne4xiajwyh”。

我的代码:

<script type="text/javascript">
  var onloadCallback = function() {
    grecaptcha.render('html_element', {
      'sitekey' : 'my_site_key'
    });
  };
</script>

<form action="#" method="POST">
  <div id="html_element"></div>
  <br>
  <input type="submit" value="Submit">
</form>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
    async defer>
</script>

我正在努力解决这个问题,因为我在网上找不到任何解决方案,并且不确定如何调试它。任何帮助将不胜感激。

由于

编辑:chrome中的错误消息:

Uncaught DOMException: Blocked a frame with origin "https://www.google.com" from accessing a cross-origin frame.
    at Dp.f.Ub (https://www.gstatic.com/recaptcha/api2/r20170213115309/recaptcha__pl.js:349:353)
    at Dp.vb (https://www.gstatic.com/recaptcha/api2/r20170213115309/recaptcha__pl.js:345:59)

2 个答案:

答案 0 :(得分:0)

您似乎必须允许跨域请求:

如果您运行apache(它也可能粘贴在.htaccess中):

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin https://www.gstatic.com
</IfModule>

或者使用php:

header("Access-Control-Allow-Origin: https://www.gstatic.com");

或者使用nginx(服务器部分):

add_header Access-Control-Allow-Origin https://www.gstatic.com; # < this is the needed header

答案 1 :(得分:0)

<head> ... <META HTTP-EQUIV="Access-Control-Allow-Origin" CONTENT="http://www.example.org"> ... </head>

Error: Permission denied to access property “document”