Copy link to clipboard
Copied
Hi,
I`m using Captivate 9 and publish in HTML5.
I have a Captivate course ("Course 1"). Within that course I embed another Captivate course ("Course 2") as a web object. Now I try to communicate between these to courses, i.e. I want to transmit the values of specific variables between the two courses. There have been several postings about this topic in this forum however it still doesn`t work.
This is what I`m doing:
In the embedded course (Course 2) I define a Captivate variable with the name variable_embedded and the value 5. In the "exterior course" (Course 1) I define a Captivate variable with the name variable_exterior without a value (or with any value).
Now I have a button in the embedded course. Clicking that button will execute the following JavaScript (via the Common JS Interface):
window.parent.window.cpAPIInterface.setVariableValue("variable_exterior", variable_embedded);
What I want to happen is that the variable_exterior takes the value of the variable_embedded (i.e. 5 in our example). However it doesn`t work. What am I doing wrong?
And additional question: How can I transmit the value of a variable the other way round - from the exterior course to the embedded course?
Thank you very much in advance for any help! I really appreciate the time you take for this!
When you insert a web object in a Captivate (CP) slide it's inserted into an iFrame in Captivate.
Here's a solution for your iFrame talking to CP issue - it worked for me.
In this example the web object is a HTML page.
i.e. In HTML page enter a number in an input field and click the Submit button.
Clicking the Submit button updates the variable value on the CP slide to match the one on the HTML page.
See image and code below.
Based on this you should be able to work out a CP talking to iFrame solution
...Copy link to clipboard
Copied
When you insert a web object in a Captivate (CP) slide it's inserted into an iFrame in Captivate.
Here's a solution for your iFrame talking to CP issue - it worked for me.
In this example the web object is a HTML page.
i.e. In HTML page enter a number in an input field and click the Submit button.
Clicking the Submit button updates the variable value on the CP slide to match the one on the HTML page.
See image and code below.
Based on this you should be able to work out a CP talking to iFrame solution.
If someone has a better solution please post it.
Regards
Donal.
HTML CODE
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function()
{
var var_embed = $("#var_emb").val();
$('#theButton').click(function()
{
var_embed = $("#var_emb").val();
window.parent.window.cpAPIInterface.setVariableValue("v_ext",var_embed);
});
});
</script>
</head>
<body>
<h1>Course 2 (Embedded)</h1>
<div id="container" class="containerClass">
<br>
<label for="var_emb">Variable_embedded</label>
<input type="text" name="var_emb" id="var_emb" value=5 />
<button type="button" id="theButton">Submit</button>
</div>
</body>
</html>
Copy link to clipboard
Copied
Thank you very much for this great answer! I discovered your answer only now, that`s why I`m answering that late.
I tried your solution and it works perfectly fine!
Could you also give me a little hint how to do it the other way round (CP talking to iFrame)? This would be extremely helpful!
(This is maybe related with my new question in Change URL of web object which addresses the problem of dynamically change the contents of a web object.)
So thanks again for your answer!
Copy link to clipboard
Copied
@michaelm:
1. Please mark "my answer" as correct to help other people (you marked it as helpful).
2. re: "Change URL of web object" query - there are quite a few suggestions given. You need to respond to say if one of these solves your problem.
If it doesn't then you have to give more information about your problem so people can help you e.g. scrrenshots of what you want to show. You may run into problems if the web objects are http web pages that are in a different domain to your web server. This Adobe link gives some information at the bottom of the page.
3. Example of CP talking to iFrame shown below: (Web Objects are inserted as iFrames on CP slides)
iFrame - WebObject (a HTML page)
!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function()
{
window.parent.updateAge = function()
{
// creates JS var "newAge" from CP "v_age" variable
var newAge = window.parent.window.cpAPIInterface.getVariableValue("v_age");
// Updates iframe Age field
$("#age").val(newAge);
}
});
</script>
</head>
<body>
<label for="age">Age</label>
<input type="text" name="age" id="age" value=0 />
</body>
</html>
Copy link to clipboard
Copied
Thank you very very much for your help and the example! What do I have to put into the script window - only the word updateAge; ? For some reason it still doesn't work - maybe there is a typo or I made something wrong. But I think I`m almost where I want to be ...
Copy link to clipboard
Copied
Oh, wait, now it works! Just made the mistake that I had already put the HTML page on the server while I ran the Captivate file locally. So I think it was blocked for security reasons. I will experiment with this a bit! (And will also give some more informations about the "Change URL of web object" question. But maybe I can already do what I like to do - I will try a little bit.)
So thanks again for your great help! This was enormously helpful for me! I have marked your answer as correct!
Copy link to clipboard
Copied
You put updateAge(); in the Scipt window.
Tips for troubleshooting:
1. See if there are any error messages in the Console tab in the browser's Development Tools (DevTools)
(e.g. open Chrome and press Ctrl + Shift + I (windows) on keyboard, and click Console tab in DevTools)
2. When re-inserting a web object on a slide - delete the web object in the CP library first.
3. Use console.log (or alert) in the script part of the HTML page to identify which part of the code is not working e.g.
$(document).ready(function()
{
console.log("Document ready");
var var_embed = $("#var_emb").val();
console.log("Initial var_embed value = " + var_embed);
$('#theButton').click(function()
{
console.log("Button clicked");
var_embed = $("#var_emb").val();
console.log("Updated var_embed value = " + var_embed);
window.parent.window.cpAPIInterface.setVariableValue("v_ext",var_embed);
console.log("CP variable updated");
});
});
Copy link to clipboard
Copied
Thank you very much! Yes, this was what I put in the script window: updateAge();
Now everything works fine! Thank you again for your help!
The "Change URL of web object" is almost working - I will describe the remaining problem in the corresponding thread now.