window.onload加載完畢的問題及解決方案(下)

接上篇,其它方法:

一、在IE中還可以在onreadystatechange事件裏進行判斷

http://www.thefutureoftheweb.com/blog/adddomloadevent

這裏有Jesse Skinner寫了一段獨立的腳本函數來解決各種瀏覽器的onload問題, adddomloadevent.js

 

代碼引用如下

 

 二、另外還有在IE中的doScroll的,這是種方法只對IE有作用,而且它是一種hack方法。

 

在MSDN:About Element Behaviors 我們可以看到

When the ondocumentready event fires, the document has been completely parsed and built. Initialization code should be placed here if the component needs to navigate the primary document structure. The ondocumentready event notifies the component that the entire page is loaded, and it fires immediately before the onload event fires in the primary document.

A few methods, such as doScroll, require the primary document to be completely loaded. If these methods are part of an initialization function, they should be handled when the ondocumentready event fires.

 

 http://javascript.nwbox.com/IEContentLoaded/

 iecontentloaded.js

 

 

在jQuery的源碼中,針對Mozilla, Opera 和webkit用的是DOMContentLoaded,也就是上一篇中第一種;

而對IE用的是doScroll的方法。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章