简体   繁体   English

其他所有内容加载完毕后,加载Recaptcha

[英]Load Recaptcha after everything else finished loading

The default way of using Recaptcha is putting: 使用Recaptcha的默认方式是:

<script src="http://www.google.com/recaptcha/api/challenge?k=publickey"></script>

where you want the Recaptcha to appear. 您希望Recaptcha出现的位置。 However, I want it to appear in the middle of the page, but I do not want it to block the rest of the page. 但是,我希望它显示在页面的中间,但是我不希望它阻止页面的其余部分。

How can I load Recaptcha last? 我如何最后加载Recaptcha?

I have jQuery loaded. 我已经加载了jQuery。

Found this code it's in JQuery. 在JQuery中找到了此代码。 When document is ready then that means the page is fully loaded. 当文档准备就绪时,则意味着页面已完全加载。

// WHEN THE DOM HAS LOADED FIRE THE reCapInsert FUNCTION TO INSERT THE reCAPTCHA
$( document ).ready(function(){
    reCapInsert();
});

// WHEN CALLED THIS INSERTS THE reCAPTCHA INTO THE PAGE
function reCapInsert(){
    Recaptcha.create('YOUR_PUBLIC_KEY_HERE',  // public key
    'recap',
        {
            theme: 'clean',
            callback: Recaptcha.focus_response_field
        }
);
}

All you really do in your HTML page place this code and it will generate a ReCaptcha in that location. 您在HTML页面中所做的全部工作都将放置此代码,它将在该位置生成一个ReCaptcha。 (Don't forget to include the recaptcha javascript in the headers of the page.) (不要忘记在页面的标题中包含recaptcha javascript。)

   <!-- The reCAPTCHA wrapper is here - this is required!! -->
    <div id="recap"></div>

Found this example of Non-Ajax version getting loaded by $(document).ready() 找到了通过$(document).ready()加载此非Ajax版本的示例

$(document).ready(function(){
    var json = {
        type: "text/javascript",
        scriptSrc: "http://www.google.com/recaptcha/api/challenge?k=6LcXq-oSAAAAAOgwSIew_xq6xkv1QUxrZbRcMz6n",
        id: "theFrame",
        iframeSrc: 'http://www.google.com/recaptcha/api/noscript?k=6LcXq-oSAAAAAOgwSIew_xq6xkv1QUxrZbRcMz6n'
    };

    var script = document.createElement('script');
    script.type = json.type;
    script.src = json.scriptSrc;

    $('<iframe>', {
       src: json.iframeSrc,
       id:  json.id,
       frameborder: 0,
        height: 300,
        width: 500
       }).appendTo('#recap');
});

JSFiddle: JSfiddle JSFiddle: JSfiddle

For more information check out the original source: Mixing jQuery and reCaptcha 有关更多信息,请查看原始源: 混合jQuery和reCaptcha

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载其他所有内容后如何加载图像? - how to load images after everything else is loaded? 我知道页面加载完成后如何运行js方法,如何强制某些js在其他所有操作之后加载? - I know how to run js methods when the page finish loading, how can I force certain js to load after everything else? jQuery、JavaScript、HTML:如何在加载其他所有内容后加载图像? - jQuery, JavaScript, HTML: how to load images after everything else is loaded? 在 Vue JS 中完成加载前一个项目之后加载每个项目 - Load each item after the one before is finished loading in Vue JS 执行代码AFTER Recaptcha.reload()完成后 - execute code AFTER Recaptcha.reload() is finished 先加载图片 - Load images before everything else 其他加载完成后,使用Webpack加载Google Analytic的gtag.js - Loading Google Analytic's gtag.js using Webpack after everything else loads 使 return 语句等待,直到函数中的其他所有内容完成 - Make the return statement wait until everything else in the function is finished 在MeteorJS中的其他所有内容之前加载JS文件 - Load a JS File before everything else in MeteorJS 在页面已经完成加载后识别页面完成加载内容 - Identify page finished loading content after page was already finished loading
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM