In developing SharePoint Framework web parts, is there any way to wait for a Modern page to load before running a piece of code?

On classic pages and in the days of Script Editor Web parts and JavaScript solutions we could simply use the _spBodyOnLoadFunctionNames array.

What am I trying to do?

I want to wait for the title banner to load on a modern page so I can ascertain its containing div's height. On a modern page the title banner may or may not have a background image, which affects the height.

How does it work?

It would be a bonus if someone could explain how a modern page loads. Are the different elements on the page (title, web parts) loaded asynchronously using AJAX calls?

  • what exactly are you waiting to get loaded ? – Gautam Sheth Oct 6 '17 at 8:24
  • I've added a bit more detail to the question. – Submits Oct 6 '17 at 8:27
  • If you only needs to check that one image then try using image.onload to make sure that it's loaded. – Thi Vo Oct 9 '17 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.