//監聽,當readystate狀態改變就觸發(loading,interactive,complete) document.onreadystatechange = function () {
console.log(document.readyState);
if (document.readyState == "loading") { //這邊一定不會進來,因為網頁一開始狀態就是loading,沒有改變,也不會觸發onreadystatechange console.log('The document is still loading.'); } if (document.readyState == "interactive") { console.log('The document has finished loading and the document has been parsed but sub-resources such as images, stylesheets and frames are still loading.'); } if (document.readyState == "complete") { // document is ready. Do your stuff here console.log('The document and all sub-resources have finished loading. The state indicates that the load event is about to fire.'); } }