2017-02-20 158 views
0

當我點擊框來確認我不是機器人時,藍色微調框開始旋轉但從未停止。最後,在瀏覽器控制檯中出現錯誤「錯誤:權限被拒絕訪問屬性」,隨後出現(看似)隨機10-15個字符的字符串,例如「rne4xiajwyh」。reCAPTCHA權限被拒絕訪問屬性

我的代碼:

<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> 

我竭力要解決這個問題,因爲我不能在網上找到任何解決辦法,我不能確定如何調試它。任何幫助將非常感激。

感謝

編輯:在鍍鉻的錯誤消息:

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) 

回答

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 
+0

如果它不工作,嘗試通過谷歌更換gstatic – Antho

相關問題