Skip to content

Instantly share code, notes, and snippets.

@luckylooke
Created August 22, 2019 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckylooke/d6731da323d9f02d9f9295bce0f7b588 to your computer and use it in GitHub Desktop.
Save luckylooke/d6731da323d9f02d9f9295bce0f7b588 to your computer and use it in GitHub Desktop.
Changing reCAPTCHA v2 lang dynamically
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