Warten Sie beispielsweise bei einem Bild, bis es geladen ist, also nachdem die Anfrage eingegangen ist, und führen Sie dann einen weiteren Vorgang aus.
Was ist mit anderen Ressourcentypen, z. B. ob die SWF-Datei geladen wird? Ist es dieselbe Methode?
Oder wie überwacht man eine HTTP-Anfrage?
歡迎選擇我的課程,讓我們一起見證您的進(jìn)步~~
瀏覽器去加載這些資源或者是異步去發(fā)http
請求的話,一般都會提供鉤子函數(shù)
。
例如,你異步去獲取js
代碼:
const script = document.createElement('script')
script.src = 'xxxx'
script.onload = script.onreadystatechange = function () {
if (!this.readyState || /^(loaded|complete)$/.test(this.readyState)) {
resolve(window[namespace][name])
sc.onload = sc.onreadystatechange = null
}
}
document.body.append(script)
你創(chuàng)建的script
對象上提供了加載的鉤子函數(shù):onload/onreadystatechange
(瀏覽器的兼容性處理),當(dāng)你把script
標(biāo)簽插入到DOM
中時,瀏覽器另開一個線程去異步加載你需要的js
資源,在加載的不同階段:this.readyState
對應(yīng)不同的值,這個時候根據(jù)需要設(shè)置你的回調(diào)函數(shù)。這樣就完成了對于一段js
代碼異步獲取的監(jiān)控。
http://stackoverflow.com/ques...
Use SWFObject to embed the SWF, then use the callback function to poll the SWF's PercentLoaded value.
If the value is 0, the SWF has not loaded yet. When it hits 100, the SWF is fully loaded.
Here's a tutorial for polling PercentLoaded, complete with code examples.