How to detect if DOMContentLoaded was fired

前端 未结 6 1961
误落风尘
误落风尘 2020-12-02 14:00

I\'m trying to help developing a library and for it I\'m trying to work with page loading.
In the process I want to make the library completely compatible with the use o

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 14:49

    If you want to know "exactly" if DOMContentLoaded was fired, you could use a boolean flag like this:

    var loaded=false;
    document.addEventListener('DOMContentLoaded',function(){
    loaded=true;
    ...
    }
    

    then check with:

    if(loaded) ...
    

提交回复
热议问题