The default way of using Recaptcha is putting:
<script src="http://www.google.com/recaptcha/api/challenge?k=publickey"></script>
where you want the Recaptcha to appear. 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?
I have jQuery loaded.
Found this code it's in 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. (Don't forget to include the recaptcha javascript in the headers of the page.)
<!-- 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(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
For more information check out the original source: Mixing jQuery and reCaptcha
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.