參考文件:Programmatically invoke the challenge
grecaptcha.ready(function() {
grecaptcha.execute('網站金鑰', {
action: 'verify2'
}).then(function(token) {
// 將 token 送到後端做驗證
});
});
<-- 引用 JS -->
<script src="https://www.google.com/recaptcha/api.js?render=網站金鑰" async defer></script>