Forum Discussion
RyanLowry
10 years agoCommunity Member
Storyline 2 Example - Generating a PDF Certificate for users who successfully complete a quiz
Hi all,
I've been experimenting with a JavaScript PDF library (pdfmake) to generate PDF certificates client side for learners who have successfully completed a quiz in Storyline 2.
You can see a...
RyanLowry
9 years agoCommunity Member
Hi Karin,
Here's one possible solution for you. The following code would replace what's currently in the JavaScript trigger.
Instead of targeting the 1st webobject (iFrame) on the page it targets a specific webobject based on the name of the src file.
Set the variable certFilename to the name of the certificate html file.
UPDATE: Fixed bug preventing this working in certain browsers
// Name of the certificate html file
var certFilename = 'certificate.html';
// HTMLCollection of elements of type iFrame
var iframeElements = document.getElementsByTagName("iframe");
// Iterate over the iFrameElements HTMLCollection
for(var i = 0; i < iframeElements.length; i++){
/* If src of current iFrame element equals the filename set in
** variable certFilename call the generatePDF() function.
*/
var src = iframeElements[i].getAttribute('src');
if (src.indexOf(certFilename) !=-1) {
iframeElements[i].contentWindow.generatePDF();
}
}