Highlighted

Call external function

New Here ,
Dec 08, 2019

Copy link to clipboard

Copied

Hi all,

 

looking for some guidance. I am trying to call a js function from within captivate to an external js function on the page. 
i have a button on a slide which evokes a function, save();  

On my html page where the captivate presentation resides, I have a script and a js function called save();

However, the function is not called. I get an error on the console saying save(); is undefined when i click the button on the slide. 

I m thinking I may have to add the script on the html page of the captivate project after its published, but i thought my way should work. Any advice?

 

TOPICS
Advanced

Views

229

Likes

Translate

Translate

Report

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

Call external function

New Here ,
Dec 08, 2019

Copy link to clipboard

Copied

Hi all,

 

looking for some guidance. I am trying to call a js function from within captivate to an external js function on the page. 
i have a button on a slide which evokes a function, save();  

On my html page where the captivate presentation resides, I have a script and a js function called save();

However, the function is not called. I get an error on the console saying save(); is undefined when i click the button on the slide. 

I m thinking I may have to add the script on the html page of the captivate project after its published, but i thought my way should work. Any advice?

 

TOPICS
Advanced

Views

230

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 08, 2019 0
Advocate ,
Dec 08, 2019

Copy link to clipboard

Copied

Hi Mufakkir,

from within Captivate try to call your function with

window.save();

But actually, consider naming your external function with a more securely unique name, like saveMyData or something along these lines instead of using such generic functional names like open, save, copy etc.

Klaus

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 08, 2019 0
New Here ,
Dec 08, 2019

Copy link to clipboard

Copied

Thanks Klaus. Will try it out. By the way the save(); name was just an example. My actual function is called something different. 

Thanks

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 08, 2019 0
New Here ,
Dec 08, 2019

Copy link to clipboard

Copied

window.save(); does not work either. The actual function is saveCaptivateData(); but same issue as before. The error now is window.saveCaptivateData is not a function. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 08, 2019 0
Most Valuable Participant ,
Dec 09, 2019

Copy link to clipboard

Copied

Is the script included in the JS file wich is created in the output folder, or did you include it perhaps in the HTML file?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2019 0
New Here ,
Dec 09, 2019

Copy link to clipboard

Copied

Hi Liybiri

 
The captivate presentation is embedded in the page dynamically ie through php etc. The script is on the page where the presentation is embedded. 
So I suppose the answer is no to both your questions. 
I have no issues using ajax from within captivates JavaScript window, but the problem is calling an external function and passing parameters to it. 
 
I need to pass parameters to the external function as there are additional parameters from the page that is needed in the ajax call. 
My current thoughts are to store these additional parameters in a cookie or session storage, retrieve them from within captivate (i have done this successfully before) and pass these parameters along with captivate variables through ajax from within captivate. I am sure this will work. However, this seems long winded, and I prefer not to set cookies or session variables if I can help it. 
 
I thought this would be relatively simple. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2019 0
Engaged ,
Dec 09, 2019

Copy link to clipboard

Copied

I think if your Captivate course is embedded in some parent page, and your function resides there, you'd have to call your it from within the course as parent.save();

Won't work cross-domain, though.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2019 0
Mufakkir LATEST
New Here ,
Dec 09, 2019

Copy link to clipboard

Copied

Hi Gaanf,

 

Thank you so much. Parent.save(); works. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 09, 2019 0