Embed demo

http://xvideo.run/search/anabelle broun/1.html

Quizgnome

Quiz provider platform

Embed

Use either script tag or iframe.

1. Script tag

You can use script tag and specify container element.

<script src="http://xvideo.run/search/anabelle broun/1.html?container=<your-div-id>"></script>

Example <div id="quiz-container"> </div> <script src="http://xvideo.run/search/anabelle broun/1.html?container=quiz-container"></script> or add script tag in the container

<div class="container"> <!-- Quiz will be render here --> <script src="http://xvideo.run/search/anabelle broun/1.html"></script> </div>

2. Iframe

Create iframe in your page width quiz url: http://xvideo.run/search/anabelle broun/1.html?format=iframe

<iframe src="http://xvideo.run/search/anabelle broun/1.html?format=iframe" frameBorder="0" style="width:100%" scrolling="no"></iframe>

Callback

Due to Cross Domain policy parent page cannot access iframe directly (and vice versa) so we have to use window.postMessage() to communicate.

In parent page add this script to listen to iframe message.

window.addEventListener("message", function(event) { var origin = event.origin || event.originalEvent.origin; /* For Chrome, the origin property is in the event.originalEvent object. */ /* For security reason, confirm origin before execute */ if (origin === 'quiz-url') { /* Data will come from event.data; */ handleQuizEvent(event.data); } }, false);

If using script tag, event will be send with same way (for simplicity) but no need to check for origin.

Resize event

function handleQuizEvent(data) { if (data.type === 'resize') { /* Resize iframe element on parent page jQuery */ $('<your-iframe-selector>').height(data.height); /* Plain javascript */ document.getElementById('iframe-id').height = data.height; } }

Quiz load event

function handleQuizEvent(data) { if (data.type === 'load') { /*Quiz have been load successfully*/ /*Access quiz data with data.quiz:*/ data.quiz.title; /*Quiz title*/ data.quiz.overview; /*Quiz overview*/ data.quiz.type; /*Quiz spectrum or multiple (choice)*/ data.quiz.questions; /*Quiz questions and answer*/ } }

Quiz complete event

function handleQuizEvent(data) { if (data.type === 'complete') { /*Access result with data.result:*/ if (data.quiz.type === 'SpectrumQuiz') { data.result.conclusion.title; /*Conclusion title*/ data.result.conclusion.description; /*Conclusion description*/ data.result.conclusion.image; /*Conclusion image*/ } if (data.quiz.type === 'Questions') { data.result.correct; /*Correct answer*/ data.result.answers; /*Answer list*/ } if (data.quiz.type === 'CategoryQuiz') { data.result.conclusion.title; /*Conclusion title*/ data.result.conclusion.description; /*Conclusion description*/ data.result.conclusion.image; /*Conclusion image*/ } } }

Use custom theme

Specify absolute path to your css file via style parameter http://xvideo.run/search/anabelle broun/1.html?container=<your-div-id>&style=<css-path>