game completed - redirection

how i can add a redirection, after the user win the game? 

where in the js i can add some like window.location.replace("http://url.com");

 

thanks for the help!

 

Alejandro

icc's picture

This is the code:

H5P.externalDispatcher.on('xAPI', function (e) { 
  if (e.data.statement.result) { 
    window.location.href="https://h5p.org"; 
  } 
});

You can add it to any .js file on your page.

Hi, thanks for the tip, but how can i redirect to a page only if game is complete without any error.
By the way, the game is a drag and drop with 8 items to place at the right places.

Thanks

otacke's picture

Hi!

Have you tried checking the results of the xAPI statement that were retrieved in the example?

Best,

Oliver 

Hi sorry for the delay and thanks to the reply !
Can you explain a little bit more how to execute that ?

Thanks in advance

otacke's picture

Hi!

Sorry, rephrasing my question: When you follow Frode's advice, what do you observe when you have a look at the xAPI statement, the result property in particular?

Best,
Oliver

Hi, thank you for your help.
Do i have to copy/paste the code in the page before seeing something ? or where can i find the xAPI statement ?
I use the WP plugin, i forget to precise this... :)

otacke's picture

Hi ErreipP!

I am a little confused. Frode's example stated: "You can add it to any .js file on your page." And yes, you then could also paste this to the browser development console and then complete an H5P exercise to see the xAPI statements that will be emitted by many content types. If you then inspect the results property (e.data.statement.result), I am sure you'll find what you're looking for.

Cheers,
Oliver

Back to the site and i realize i did not thank you.
So, thanks a lot and appologies for the late reply. :)

Hi, thanks for the tip, but how can i redirect to a page only if game is complete without any error.

By the way, the game is a drag and drop with 8 items to place at the right places.

Thanks