Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex SmartCaptcha
  • Getting started
    • All guides
    • Creating a CAPTCHA
    • Deleting a CAPTCHA
    • Obtaining the keys
    • Advanced method of adding the widget
    • Verifying the CAPTCHA response
    • Viewing operations on service resources
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes

In this article:

  • Adding the SmartCaptcha widget using the advanced method
  • Adding a SmartCaptcha widget with on-demand loading
  • What's next
  1. Step-by-step guides
  2. Advanced method of adding the widget

Adding the SmartCaptcha widget

Written by
Yandex Cloud
Updated at May 15, 2026
  • Adding the SmartCaptcha widget using the advanced method
  • Adding a SmartCaptcha widget with on-demand loading
  • What's next

Adding the SmartCaptcha widget using the advanced methodAdding the SmartCaptcha widget using the advanced method

You can control the widget loading process via the window.smartCaptcha object. However, in this guide, we will use the onloadFunction callback function:

  1. Add the widget’s JS script to the user’s page by placing the following code inside the <head> tag (or anywhere on the page):

    <script
        src="https://smartcaptcha.cloud.yandex.ru/captcha.js?render=onload&onload=onloadFunction"
        defer
    ></script>
    
  2. Add an empty container on the page. The system will use it to insert the widget:

    <div id="<container_ID>"></div>
    

    Where id is a random identifier.

  3. Add the callback function code on the page:

    <script>
        function onloadFunction() {
        if (window.smartCaptcha) {
            const container = document.getElementById('<container_ID>');
    
            const widgetId = window.smartCaptcha.render(container, {
                sitekey: '<client_key>',
                hl: '<language>',
            });
        }
        }
    </script>
    

    Where:

    • <container_ID>: ID that was generated at the previous step.
    • sitekey: Client-side key.
    • hl: Language used for the widget and the challenge.

    Consider adding an existence check for the window.smartCaptcha object in the callback function. It will prevent errors caused by calling the function before the script has finished loading.

    Note

    Upon loading, the widget adjusts its container height to 100px, which may cause an unwanted layout shift. To avoid the layout shift, set the container height to 100px prior to the widget being loaded.

    <div ... style="height: 100px"></div>
    

Adding a SmartCaptcha widget with on-demand loadingAdding a SmartCaptcha widget with on-demand loading

To add a widget with on-demand CAPTCHA loading, use the following approach:

window.onloadFunction = () => {
  if (window.smartCaptcha) {
    // Creating a CAPTCHA
  }
}

function handleScriptLoadingError() {
  // Error handling
}

const scriptElement = document.createElement('script');
scriptElement.src = 'https://smartcaptcha.cloud.yandex.ru/captcha.js?render=onload&onload=onloadFunction';
scriptElement.onerror = handleScriptLoadingError;
document.body.appendChild(scriptElement);

What's nextWhat's next

  • Invisible CAPTCHA.
  • Integrating CAPTCHA in React.

Was the article helpful?

Previous
Obtaining the keys
Next
Verifying the CAPTCHA response
© 2026 Direct Cursus Technology L.L.C.