Skip to main content
February 29, 2016
Answered

Buttons dynamically link to same web object all displaying different PDF's

  • February 29, 2016
  • 1 reply
  • 266 views

I am using a web object to display a PDF. This seems to be the best way to actually show a PDF inside of a captivate 9 training module (I could be wrong).

The ultimate goal is to have the buttons pull a URL of a PDF from a database and display said PDF on a web object. I can hardcode a PDF URL into a web object quite easily but I am having trouble figuring out to to show a specific PDF once a button has been clicked.

Any advice?

This topic has been closed for replies.
Correct answer

I was able to figure out a solution to the problem.

I updated all documents to a database and I was able to show those documents in my captivate module. This was done by supplying the web object with a relative path to that document. The following script was attached to the buttons.

try {

    window.iFrameReference;

    window.frm;

    /* Detect SWF or HTML5 output */

    if(typeof window.cp === 'undefined'){

        /* We have SWF output */

        window.iFrameReference = $("iframe[id^='helloiframe']")[0];

    } else {

        /* We have HTML5 output.  Change the Item Name Below */

        window.frm = $("#WebObject iframe")[0];

        

        /* HTML5 output has nested iframes so get a reference to the inner iframe */

        /*window.iFrameReference = frm.contentWindow.$('#helloiframe')[0];*/

    }

    /* Get the web address from Captivate */

    var webAddress = window.cpAPIInterface.getVariableValue('File1');

    

    /* Change the source of the iframe to the cp variable */

    window.frm.src = webAddress;

    

}catch(err){

    window.console.log(err);

}

Where WebObject was the name of the web object that I placed in my module and File1 was the local variable I created that that stored the relative path to the document in the DB.

1 reply

Correct answer
April 6, 2016

I was able to figure out a solution to the problem.

I updated all documents to a database and I was able to show those documents in my captivate module. This was done by supplying the web object with a relative path to that document. The following script was attached to the buttons.

try {

    window.iFrameReference;

    window.frm;

    /* Detect SWF or HTML5 output */

    if(typeof window.cp === 'undefined'){

        /* We have SWF output */

        window.iFrameReference = $("iframe[id^='helloiframe']")[0];

    } else {

        /* We have HTML5 output.  Change the Item Name Below */

        window.frm = $("#WebObject iframe")[0];

        

        /* HTML5 output has nested iframes so get a reference to the inner iframe */

        /*window.iFrameReference = frm.contentWindow.$('#helloiframe')[0];*/

    }

    /* Get the web address from Captivate */

    var webAddress = window.cpAPIInterface.getVariableValue('File1');

    

    /* Change the source of the iframe to the cp variable */

    window.frm.src = webAddress;

    

}catch(err){

    window.console.log(err);

}

Where WebObject was the name of the web object that I placed in my module and File1 was the local variable I created that that stored the relative path to the document in the DB.