HTML Snippet containing jQuery loading order

1
Hi,  I have implemented a HTML snippet in my application, however it is running before the content it is targeting has loaded. Is there a way to order the sequence the content is run or make the snippet load last.    Cheers
asked
2 answers
2

This question has been asked a couple of times before, also by me ;) 

https://forum.mendix.com/link/questions/7418

The ready function does not add anything in terms of loading after the content / other widgets have loaded.  

  • Best option, if a context entity is needed, create a simple custom widget which needs a context entity. In that way you ensure the code is triggered after the entity is loaded into the page.
  • Other option:
    • If your page is simple, so not too much conditional visibility and too many layered dataviews, you can get away with a simple timeout as Austin is mentioning.
    • If the page is more complex, add a script that will check for some 10 seconds every interval of 100 ms. If it finds the HTML element, trigger your code targeting the just created HTML element and exit the loop. If the HTML element is not loaded within 10 seconds the loop will end either way. That will work in most cases, but be aware, it needs some proper JS programming.

 

Good luck!

answered
2

Hi Dan,

You can use the jquery ready function as well as a time out to make sure your page loads before the script is executed.

I usually use something along the lines of this.

jQuery(document).ready(function() { 

   setTimeout(function() { 

   
 

}, 100); 

 

}); 

 

 

Hope this helps!

answered