Calling function from outside of Saola

Hi,

We have a “framework” which will load up html files, i.e. ones built in Saola, and display them. We also have some functions in the “framework” that I need to call, lockNext() and unlockNext(), which will enable or disable the Next button in then navigation area.

In Saola I have a javascript function, addToClicks, which will keep track of the total number of buttons that have been clicked. Then when certain conditions are met, I need to call unlockNext();

How do I call functions outside of Saola ?
These functions,along with other things, and some jQuery, are in a javascript file which are called from the html file -
<script src="js/framework.js"></script>

Thanks.

Hi,

You can call any public functions in framework.js via the global object of the framework.

If the framework and Saola Animate HTML5 are embedded into the same HTML document, they share the same global window object. You can call framework functions such as lockNext(), unlockNext() directly from Saola Animate.

If Saola Animate HTML5 is embedded into an iframe in the HTML document that contains framework.js, the framework global window object is the parent of the HTML5 global window object:

// in Saola Animate
var frameworkWin = window.parent;
frameworkWin.lockNext();

You can see this tutorial for more information about embedding Saola Animate HTML5 directly or through an iframe:

Regards

Hi,

Thank you for the response.

I’m not sure what I’m doing wrong but its not working.

In Firefox web developer tools - logs I get this message if I use this code

var frameworkWin = window.parent;
frameworkWin.lockNext();

error message -
“DOMException: Permission denied to access property “lockNext” on cross-origin object”

If I just call the function lockNext(); in the browser logs its says “ReferenceError: lockNext is not defined”

here are the functions as in the js file.

function unlockNext()
{
		is_next_locked = false; 
}
function lockNext()
{
	is_next_locked = true;
}

not sure if this matters but this what we have this for displaying the html pages .

 $("#container").html('<object type="text/html"data="'+links[c]+'">'+'</object>');

Thank you.

Oh wait. It was running from the desktop not from the server. I think that’s why I was getting ““DOMException: Permission denied to access property “lockNext” on cross-origin object”” error.

Hi,

To access your framework functions, Saola Animate HTML5 must be hosted on the same origin with the framework.

Regards

Hi,

yep. After uploading it to our server it worked. It was late and was trying to test it locally on my desktop.

Anyway thank you. This helped a lot.

1 Like