For example, for a picture, wait until it is loaded, that is, after the request is received, and then perform another operation.
What about other resource types, such as whether the swf is loaded? Is it the same method?
Or how to monitor an http request?
The browser loads these resources or sends them asynchronously
http
请求的话,一般都会提供钩子函数
.For example, you get the
js
code asynchronously:The
script
object you created provides a loading hook function:onload/onreadystatechange
(browser compatibility processing), when you putscript
When the tag is inserted intoDOM
, the browser opens another thread to asynchronously load the resources you need. At different stages of loading:this.readyState
corresponds to different values. , set your callback function as needed at this time. This completes the monitoring of asynchronous acquisition of a piece of code.script
对象上提供了加载的钩子函数:onload/onreadystatechange
(浏览器的兼容性处理),当你把script
标签插入到DOM
中时,浏览器另开一个线程去异步加载你需要的js
资源,在加载的不同阶段:this.readyState
对应不同的值,这个时候根据需要设置你的回调函数。这样就完成了对于一段js
onload event or readystatechange event, but not all objects support it. In addition, promises should also work
http://stackoverflow.com/ques...
You can consider ajax or fetch API