I have a web form that uses reCAPTCHA to filter out robots. The form has a <script>
tag that loads the captcha challenge in an <iframe>
. If this script fails to load, then the captcha challenge would not appear and no one would be able to send a post.
Is there any way that I can detect whether the script is loaded so that I can turn off this feature from my side?
I have a web form that uses reCAPTCHA to filter out robots. The form has a <script>
tag that loads the captcha challenge in an <iframe>
. If this script fails to load, then the captcha challenge would not appear and no one would be able to send a post.
Is there any way that I can detect whether the script is loaded so that I can turn off this feature from my side?
Share asked May 7, 2012 at 2:45 Question OverflowQuestion Overflow 11.3k20 gold badges81 silver badges113 bronze badges 1- i would suggest you to use requirejs , but i think you are looking for a fast solution – wizztjh Commented May 7, 2012 at 2:47
3 Answers
Reset to default 5Attach the load
event to the script
element which points to reCAPTCHA.
var script = document.createElement("script");
script.addEventListener("load", function() {
// Script has loaded.
});
script.src = "/path/to/recaptcha.js";
document.body.appendChild(script);
You could probably find a way to do that detection, but I wouldn't remend it, as it defeats the purpose of the captcha. A puter/robot could easily make the script not load. A hosts file entry would do the trick.
A script could also be made that just executes your handling for the failed to load case, thereby circumventing your captcha.
script.addEventListener wont work on IE8 and IE7. for that you need to
if (!script.addEventListener) {
script.attachEvent("onload", function(){
// script has loaded in IE 7 and 8 as well.
});
}
else
{
script.addEventListener("load", function() {
// Script has loaded.
});
}