0

Is there a DOM event that fires when (in addition to all of the DOM elements being loaded including images, stylesheets etc.) some initial Javascript finishes fetching data and then updates DOM?

The use case is in a closed system where I am calling window.print() to open a print dialog, but only once full page is loaded and all Javascript returns its data.

I have tried using MutationObserver, but it fires multiple times and I need it to fire only once when all of the loading is finished.

I have a workaround ready (by creating a Custom Event and firing it when scripts finish), but I am wondering if there is some kind of built-in event that is capable of this.

Michael Munta
  • 207
  • 2
  • 16
  • 2
    I don't believe so, and if there was would it be a benefit in your case, since you have JavaScript waiting for the "all JavaScript has finished" event which wouldn't fire because some of your JavaScript is waiting for that event? To be clear, I think - though I'd be interested in being proven wrong - that the`customEvent` is your best bet. – David Thomas May 19 '21 at 09:15
  • If you are specifically waiting for all ```ajax``` events to be completed, look at: https://stackoverflow.com/questions/287188/how-to-know-when-all-ajax-calls-are-complete – prettyInPink May 19 '21 at 09:17
  • @prettyInPink Not an `ajax` case here, but that is exactly what I'm looking for. – Michael Munta May 19 '21 at 09:44

0 Answers0