2017-08-09 56 views
1

我加入谷歌的v2的的Recaptcha有問題像這樣一個骨幹視圖:刪除的Recaptcha v2的有問題正在得到解決後

// this is the callback function 
var getRecaptchaResponse = function (response) { 
    if (response) { 
     thisView.captchaResponse = response; 
     thisView.canShowContinue(); 
    } else { 
     alert("Captcha response was incorrect"); 
    } 
}; 

// render the recaptcha 
var renderCaptcha = function() { 
    thisView.captchaWidgetId = grecaptcha.render('recaptcha-container', { 
     sitekey: GlobalSettings.recaptchaKey, 
     callback: getRecaptchaResponse, 
     size: 'compact' 
    }); 
}; 

// map the internal function to the window 
// so that the callback registered in the 
// link below can be called by JSONP. 
window.renderCaptcha = renderCaptcha; 

// load the script 
$.getScript('https://www.google.com/recaptcha/api.js?onload=renderCaptcha&render=explicit', function() { }); 

一旦Captcha驗證碼被成功地解決了我想從用戶界面中刪除它,所以我「M簡單地移除div容器:

// if the user has solved the captcha yet, don't continue 
if (!thisView.captchaResponse) { 
    return; 
} 

// remove recpatcha 
$('#recaptcha-container').remove(); 

似乎沒有要,谷歌已經提供給摧毀grecaptcha部件雖然一個正確API method。這是一個問題嗎?推薦的方法是什麼?

以上移除的容器在Chrome中運行,但不在IE11中運行。在IE11中,驗證碼挑戰仍然可見。

+0

您的意思是編程驗證碼對象? – Ezenhis

+0

@Ezenhis正好。我正在尋找'grecaptcha.remove('recaptcha-container');'或者其他類似的東西。 – Junto

回答

1

按照驗證碼的常見問題,似乎移出容器後,你應該重新使用grecaptcha.reset(id)

https://developers.google.com/recaptcha/docs/faq

I'm getting an uncaught SecurityError: blocked a frame with origin " https://www.google.com " from accessing a frame with origin "". What should I do?

This typically occurs if the reCAPTCHA widget HTML element is programmatically removed sometime after the end user clicks on the checkbox. We recommend using the grecaptcha.reset() javascript function to reset the reCAPTCHA widget.

+0

我沒有收到任何錯誤,但現在可以解決問題。取出容器並調用reset()後,驗證屏幕現在消失。謝謝。 – Junto

+0

我知道,我只是想保持「這通常發生[...]」在報價中的上下文;)很高興幫助:) – Ezenhis

+0

我注意到,在Chrome中,不需要重置,而是拋出一個Javascript錯誤,但在IE中是必需的。所以我現在有一個檢查,看看它是否是IE瀏覽器,只有運行該重置。 – Junto