How to check if DOM is ready without a framework?

前端 未结 6 1256
有刺的猬
有刺的猬 2020-11-27 12:39

The question is so like a zillion others here and on the web - How to check if DOM has loaded in Javascript? But here\'s the catch:

  • Without using a framework l
6条回答
  •  清歌不尽
    2020-11-27 13:17

    If relying on document.readyState is ok, quick-and-dirty solution with polling:

    (function() {
        var state = document.readyState;
        if(state === 'interactive' || state === 'complete') {
            // do stuff
        }
        else setTimeout(arguments.callee, 100);
    })();
    

提交回复
热议问题