Do you have a postmessage API?
Yes, indeed!
The Postmessage API is used to send some extra information to your embedding page of our exams. The next part is a bit technical so bear with us. The postMessage API will now push a message that will look something like this:
{
status: 'ranking',
ranking: {
score: 50, // Number, the mark for the exam. 100 means 100% correct, 0 means 0% correct correct
answered: 2, // Number, The amount of answered questions for this session
correct: 1, // Number, the amount of questions that were answered (partially) correct
incorrect: 1, // Number, the amount of questions that were answered wrong
points: 2, // Number, The amount of points scored for this session
maximum: 4, // Number, the maximum amount of possible points for this session
category: {
title: 'Failed' // String,
}
}
}
For your ease below I've added a sample JavaScript that you can use on your embedding page. It makes use of the jQuery library, but that requirement can be quite easily removed if necessary.
<script type="text/javascript>
// Sample implementation of events. Using jQuery v1.7 or higher
// Should work on following browsers: http://caniuse.com/#feat=x-doc-messaging
jQuery(window).on("message onmessage", function(event) {
var origin = event.originalEvent.origin;
var allowedDomains = [
'https://www.onlinequizcreator.com',
'https://www.onlineassessmenttool.com',
'https://www.onlineexambuilder.com',
'https://www.easy-lms.com'
];
try {
var data = (typeof event.originalEvent.data === "string") ? JSON.parse(event.originalEvent.data) || event.originalEvent.data;
}
catch (e) {
return;
}
if (allowedDomains.indexOf(origin) !== -1 && data.status && data.ranking) {
// Your custom script....
// The following variables are available
data.ranking.score; // The mark in (%) for this exam. eg. 100 for everything correct and 0 when every answer was wrong
data.ranking.answered; // The total amount of answered questions
data.ranking.correct; // Amount of correctly answered questions
data.ranking.incorrect; // Amount of wrong answered questions
data.ranking.points; // The amount of points that the particpant got for this session
data.ranking.maximum; // The maximum possible points for this exam
data.ranking.category.title; // The name of the category the particpant falls in. Likely to be 'Passed' or 'Failed'
}
});
</script>
If there are some problems with the implementation you know to find our support at support@onlinequizcreator.com