Skip to content

Commit f97251d

Browse files
committed
Fixed bug where multiple recaptcha were unable to render
1 parent 14cf23c commit f97251d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

vuejs/GoogleReCaptchaV3.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,26 @@
3737
},
3838
methods: {
3939
init() {
40-
if (!('grecaptcha' in window)) {
40+
if (!document.getElementById('gRecaptchaScript')) {
4141
42-
window.gRecaptchaOnLoad = this.render;
42+
window.gRecaptchaOnLoadCallbacks = [this.render];
43+
window.gRecaptchaOnLoad = function () {
44+
for (let i = 0; i < window.gRecaptchaOnLoadCallbacks.length; i++) {
45+
window.gRecaptchaOnLoadCallbacks[i]();
46+
}
47+
delete window.gRecaptchaOnLoadCallbacks;
48+
delete window.gRecaptchaOnLoad;
49+
};
4350
4451
let recaptchaScript = document.createElement('script');
4552
recaptchaScript.setAttribute('src', 'https://www.google.com/recaptcha/api.js?render=explicit&onload=gRecaptchaOnLoad');
53+
recaptchaScript.setAttribute('id', 'gRecaptchaScript');
4654
recaptchaScript.async = true;
4755
recaptchaScript.defer = true;
4856
document.head.appendChild(recaptchaScript);
4957
58+
} else if (!window.grecaptcha || !window.grecaptcha.render) {
59+
window.gRecaptchaOnLoadCallbacks.push(this.render);
5060
} else {
5161
this.render();
5262
}

0 commit comments

Comments
 (0)