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

Call external function

New Here ,
Dec 08, 2019 Dec 08, 2019

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

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

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

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

Thanks

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

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. 

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
LEGEND ,
Dec 09, 2019 Dec 09, 2019

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?

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

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

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.

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

Hi Gaanf,

 

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

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