What is the best way to determine when Lectora's scripts are complete/page objects are available?

We have some actions and rungroups that are being called from javascript. This worked just fine in Lectora 16 (and before), but in Lectora 21 objects are being rendered later, so am having issues with the actions/rungroups being called before the objects are available on the page. Does anyone know the best way to determine when Lectora's scripts are complete and all page objects are available?

Discussion (4)

Have you tried having the JavaScript triggered by the object's "OnShow" event?

Thanks for the suggestion. Our script runs at the top level, and if we were to change it to on OnShow event, it would have to be done on the last object of every page, so that wouldn't be feasible for us. I have successfully used the following code that looks at the Lectora variable bPageLoaded.

var loadInt=setInterval(start,100);

function start(){

if(bPageLoaded){

clearInterval(loadInt);

//Code to run

}

}

Here is some updated information and actual script from someone at eLearning Brothers:

The easiest way to run your scripts after a page has been loaded in a portable fashion is to have a Lectora Action run On Show of the Project, or a specific chapter, section or page.

That's the best guidance to make your scripting work for Lectora Desktop and Online, for Seamless Play and non-Seamless Play publishing options.

Add the following to a javascript action (preferred), or if updating script, it can be used in the javascript code:

$(window).ready(doAfterLectoraLoad); 

Javascript functions:

function doAfterLectoraLoad() {

if(!window.bPageLoaded) {//we want it to match

setTimeout(doAfterLectoraLoad, 50);//wait 50 millisecnds then recheck

return;

}

afterLectoraLoad();

}

function afterLectoraLoad() {

//Enter the code to run after Lectora is loaded

}

Because the Lectora Action is always run after the Lectora page is loaded, there is a correction:

Example if using the Lectora Run Javascript:

Javascript in Lectora:

afterLectoraLoad();

Javascript code:

function afterLectoraLoad() {

//Enter the code to run after Lectora is loaded

}

If using in Script only:

Javascript code:

$(window).ready(doAfterLectoraLoad); 

function doAfterLectoraLoad() {

if(!window.bPageLoaded) {//we want it to match

setTimeout(doAfterLectoraLoad, 50);//wait 50 millisecnds then recheck

return;

}

afterLectoraLoad();

}

function afterLectoraLoad() {

//Enter the code to run after Lectora is loaded

}