getting maximum score before interaction

Forums: 

Hi guys,

I need to get score of a content once it loads in iframe before user clicks check answer. Is that possible?

I created the content in wordpress using h5p plugin. using the embeded iframe in another website. so i need to get the maximum score in display in my page.

Can anyone please suggest me some ideas.

otacke's picture

Hi!

You could call `getMaxScore()` on the content instance of most content types (see https://h5p.org/documentation/developers/contracts), but this will not work if the iframe source is on a different domain. Browsers prevent cross-origin access via iframes for good reasons, and H5P does not provide another mechanism to ask for the maximum score.

Best,

Oliver 

H5P.externalDispatcher.on('xAPI', function (event) {  window.parent.postMessage(event.data, '*');}); I am using this method to pass score to embeded iframe during onload. But after check only i can get event.data json before that i cant access it.
otacke's picture

So you have control over the server side that's embedded from, too? Then don't wait for xAPI data to be sent, but wait until the content is initialized and call`getMaxScore` on the instance and return that result via post messaging.

Do you have any sample to get getMaxScore during loading?

thanks for your support.

otacke's picture

You can wait for the external dispatcher to send `initialized` and then check `H5P.instances` for your instance that you can call `getMaxScore()`on. What do you need this for by the way?

otacke's picture

Hey! Just checking your progress. Did you figure it out?

H5P.externalDispatcher.on('xAPI', function (event) {console.log(event.data);  window.parent.postMessage(event.data, '*');}); I am using this inside iframe script once user gave check then only i am getting the message in parent component. Is there any function which will allow to send message onloading the component?

H5P.externalDispatcher.on('xAPI', function (event) {console.log(event.data);  window.parent.postMessage(event.data, '*');}); I am using this inside iframe script once user gave check then only i am getting the message in parent component. Is there any function which will allow to send message onloading the component?