M
M
m1kz2021-07-07 13:35:48
JavaScript
m1kz, 2021-07-07 13:35:48

How to download recaptcha v2 via js?

Here is the code that works but .g-recaptcha doesn't display the recaptcha. How to fix?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://code.jquery.com/jquery-3.0.0.min.js"
            integrity="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0=" crossorigin="anonymous"></script>
    <script src="//www.google.com/recaptcha/api.js"></script>
</head>
<body>
<div class="recaptcha"></div>

<button class="button">Кнопка</button>
<script>
    i = 0;
    $('.button').click(function () {
        if (i % 2) {
            $('.recaptcha')[0].innerHTML = '<div class="g-recaptcha"  data-sitekey="6LcXdm8bAAAAAIfagC-DXbNuWUiEstmlfG04eskc"></div>'
        } else {
            $('.recaptcha')[0].innerHTML = ''
        }
        i++
       //console.log(i)
    })
</script>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question