參考文件:Explicitly render the reCAPTCHA widget
var onloadCallback = function() {
grecaptcha.render('插入在哪個 id 中', {
'sitekey': '網站金鑰',
'theme': 'light',
'size': 'normal',
'callback': verifyCallback,
'expired-callback': expired,
'error-callback': error
});
function verifyCallback(token) {
// 把 token 跟 ip 送到後端做驗證
}
}
<-- 引用 JS -->
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>