Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
    • Cloud Interconnect
    • Cloud Backup
    • Cloud Registry
    • Yandex AI Studio
    • Compute Cloud
    • Object Storage
    • Managed Service for Kubernetes®
    • Yandex BareMetal
    • Smart Web Security
    • Security Deck
    • Managed Service for PostgreSQL
    • Managed Service for ClickHouse®
    • Monium
    • Cloud CDN
    • Network Load Balancer
    • Virtual Private Cloud
    • Cloud DNS
    • Application Load Balancer
    • Yandex Cloud Video
    • Stackland
    • Yandex Cloud Router
    • Yandex Managed Service for Trino
    • Managed Service for MySQL®
    • Managed Service for Valkey™
    • Managed Service for Apache Spark™
    • Yandex StoreDoc
    • Managed Service for OpenSearch
    • Managed Service for Apache Kafka®
    • Data Transfer
    • Yandex MPP Analytics Engine for PostgreSQL
    • Yandex Managed Service for Apache Airflow®
    • Data Processing
    • Yandex MetaData Hub
    • Managed Service for YDB
    • Managed Service for Sharded PostgreSQL
    • Managed Service for YTsaurus
    • Yandex WebSQL
    • DataLens
    • Yandex Search API
    • SpeechSense
    • SpeechKit
    • DataSphere
    • Vision OCR
    • Translate
    • Yandex Identity Hub
    • Key Management Service
    • Certificate Manager
    • Yandex Lockbox
    • Audit Trails
    • SmartCaptcha
    • Cloud Desktop
    • SourceCraft Code Assistant
    • Container Registry
    • Managed Service for GitLab
    • Managed Service for Prometheus®
    • Cloud Functions
    • API Gateway
    • Yandex Cloud Postbox
    • Message Queue
    • Serverless Integrations
    • IoT Core
    • Data Streams
    • Serverless Containers
    • Cloud Notification Service
    • Yandex Query
    • Identity and Access Management
    • Yandex Cloud Console
    • Resource Manager
    • Yandex Cloud Billing
    • Yandex Cloud Quota Manager
    • Cloud Apps
  • 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
    • Migrating to the new condition format in the API, CLI, and Terraform
  • 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
View in Markdown
  • 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.