Skip to main content
Inspiring
April 12, 2016
Answered

incomplete script in advanced actions

  • April 12, 2016
  • 1 reply
  • 440 views

Hi, everyone!  I have a problem that I cant figure out.  I've received an existing course from another developer and they have an advanced action set to execute javascript - the code is as follows:

Original code

var winRef = window.open("", "targetWindow", "height=400, width=400, menubar=no, scrollbars=yes", false);

var slideRef = window.cpAPIInterface.getCurrentSlideIndex();

var transc = $("#transcript_" + slideRef + "accStr" ).text();

var doc = winRef.document;

doc.open("text/html");

doc.write(transc);

doc.close();

This works, but it's not displaying the text formatting correctly, so i changed it to this:

Updated code

var winRef = window.open("", "targetWindow", "height=400, width=400, menubar=no, scrollbars=yes", false);

var slideRef = window.cpAPIInterface.getCurrentSlideIndex();

var transc = $("#transcript_" + slideRef + "accStr" ).text();

var splitText = transc.split("|");

var doc = winRef.document;

doc.open("text/html");

for (i=0; i<splitText.length; i++)

{

    doc.write(splitText + "<br><br>");

};

doc.close();

This code works great when tested in a separate, standalone HTML page, but whenever I try to update it in advanced actions, it wont take changes.  When taking things out line by line, I found out it's the for loop that Captivate doesnt like.

What am I missing here?  Thanks guys!

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    Generally you can't use a for loop in the JS window.

    1 reply

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    April 12, 2016

    Generally you can't use a for loop in the JS window.

    anton9800Author
    Inspiring
    April 12, 2016

    Thanks!  Should I just stick with regular "Execute JavaScript" instead of "Execute Advanced Actions" then?

    P.S.  Could you tell me why for loops are not allowed here? 

    TLCMediaDesign
    Inspiring
    April 12, 2016

    It won't make any difference. They are both still in the same JS window. You'll need to do what you want in an included JS file of put it in the head of the html. Put the script in a function and call that function within the JS window.