Cross Browser Dom Ready

前端 未结 3 1484
夕颜
夕颜 2020-12-23 17:43

I inherited this piece of code and it seems suboptimal and possibly incorrect since it\'s adding event listeners on both the window and document objects. However, it is wor

3条回答
  •  青春惊慌失措
    2020-12-23 18:31

    If you want to know how it's done or see a way of doing it. I recommend looking at Diego Perini's work. His work and methods are used in many DOM libraries, including jQuery. The guy doesn't seem to get much credit unfortunately. He is the one who pioneered the try/catch polling method, which is what makes cross-browser dom loaded events possible when IE is thrown into the mix.

    https://github.com/dperini/ContentLoaded/blob/master/src/contentloaded.js

提交回复
热议问题