Check when async javascript file is loaded [duplic

2019-02-26 02:47发布

This question already has an answer here:

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>

1条回答
神经病院院长
2楼-- · 2019-02-26 03:33

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>
查看更多
登录 后发表回答