Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

incomplete script in advanced actions

Participant ,
Apr 12, 2016 Apr 12, 2016

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!

371
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Apr 12, 2016 Apr 12, 2016

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

Translate
People's Champ ,
Apr 12, 2016 Apr 12, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 12, 2016 Apr 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? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 12, 2016 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 12, 2016 Apr 12, 2016

I appreciate your help, thank you!

Before I got your response I tried it in a Execute JavaScript, and it actually worked, although after reading your comment I'm not sure if it's a good solution.

Could you tell me what the easiest way is to add a function to head of html so it's there when published (so I dont have to add it manually every time I republish)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 12, 2016 Apr 12, 2016
LATEST

Sometimes they do and sometimes they don't. I personally never use the script window. I edit the html template to include the js file and a css file and store those files in the applicable assets folders.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources