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

Call external function

New Here ,
Dec 08, 2019 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

450

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
community guidelines
Advocate ,
Dec 08, 2019 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

Votes

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
community guidelines
New Here ,
Dec 08, 2019 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

Votes

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
community guidelines
New Here ,
Dec 08, 2019 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. 

Votes

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
community guidelines
Community Expert ,
Dec 09, 2019 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?

Votes

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
community guidelines
New Here ,
Dec 09, 2019 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. 

Votes

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
community guidelines
Engaged ,
Dec 09, 2019 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.

Votes

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
community guidelines
New Here ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

LATEST

Hi Gaanf,

 

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

Votes

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
community guidelines
Resources
Help resources