Is there a way to determine if an external javascript file is fully loaded?

I have a web form that uses reCAPTCHA to filter robots. The form has a tag <script>that loads captcha's call <iframe>. If this script does not load, then the captcha call will not appear and no one will be able to send the message.

Is there any way I can determine if the script is loaded so that I can disable this function on my part?

+5
source share
3 answers

Attach an event loadto an element scriptthat 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);
+6
source

, , , captcha. / script. .

A script , , captcha.

+2

script.addEventListener will not work with IE8 and IE7. for this you need

  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.
    });
}
+1
source

All Articles