检查异步JavaScript文件何时加载 [英] Check when async javascript file is loaded
本文介绍了检查异步JavaScript文件何时加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在所有异步文件加载完毕后才引导我的页面。有什么方法可以在异步文件加载时得到通知?
index.html
< script src =fileone.jstype =text / javascriptasync>< / script>
< script src =filetwo.jstype =text / javascriptasync>< / script>
< script src =bootstrap.jstype =text / javascriptasync>< / script>
解决方案
给你的一个脚本一个ID ...
< script src ='fileone.js'type ='text / javascript'async id ='script_1'>< /脚本>
< script>
document.getElementById(script1)。onload = script.onreadystatechange = function(){alert(Script loaded!); }
< / script>
I'd like to "bootstrap" my page only after all async files have been loaded. Is there a way I can be notified when an async file has been loaded?
index.html
<script src="fileone.js" type="text/javascript" async></script>
<script src="filetwo.js" type="text/javascript" async></script>
<script src="bootstrap.js" type="text/javascript" async></script>
解决方案
Giving one of your scripts an ID...
<script src='fileone.js' type='text/javascript' async id='script_1'></script>
<script>
document.getElementById("script1").onload = script.onreadystatechange = function(){ alert("Script loaded!"); }
</script>
这篇关于检查异步JavaScript文件何时加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文