How to execute code before window.load and after DOM has been loaded?

前端 未结 4 1858
鱼传尺愫
鱼传尺愫 2020-12-09 08:36

Here is the circumstance: I have 2 pages:

  • 1 x html page
  • 1 x external Javascript

Now in the html page, there will be internal Ja

4条回答
  •  半阙折子戏
    2020-12-09 09:33

    If you want something to be done right away without waiting for any event then you can just do it in the JavaScript - you don't have to do anything for your code to run right away, just don't do anything that would make your code wait. So it's actually easier than waiting for events.

    For example if you have this HTML:

    then whatever code is in your-script.js will be run after the div with id=one but before the div with id=two is parsed. Just don't register event callbacks but do what you need right away in your JavaScript.

提交回复
热议问题