Created
August 22, 2019 15:03
-
-
Save luckylooke/d6731da323d9f02d9f9295bce0f7b588 to your computer and use it in GitHub Desktop.
Changing reCAPTCHA v2 lang dynamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setCaptchaLang(lang) { | |
const container = document.getElementById('captcha_container'); | |
// Get GoogleCaptcha iframe | |
const iframeGoogleCaptcha = container.querySelector('iframe'); | |
// Get language code from iframe | |
const actualLang = iframeGoogleCaptcha.getAttribute("src").match(/hl=(.*?)&/).pop(); | |
// For setting new language | |
if (actualLang !== lang) { | |
iframeGoogleCaptcha.setAttribute("src", iframeGoogleCaptcha.getAttribute("src").replace(/hl=(.*?)&/, 'hl=' + lang + '&')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment