[英]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.