有没有办法检测外部JavaScript文件是否已完全加载? [英] Is there a way to detect whether an external javascript file is fully loaded?

查看:83
本文介绍了有没有办法检测外部JavaScript文件是否已完全加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 reCAPTCHA 来过滤机器人的网络表单。该表单有一个< script> 标记,用于在< iframe> 中加载验证码质询。如果此脚本无法加载,则不会出现验证码质询,也无法发送帖子。

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?

推荐答案

附加加载指向reCAPTCHA的脚本元素的事件。

Attach 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);

这篇关于有没有办法检测外部JavaScript文件是否已完全加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆