Copy link to clipboard
Copied
I have an html 5 captivate 9 project. I have a custom .js file that contains functions used in the project. After I publish my project, I am adding a <script> tag to include my custom .js file. Is there a "best practices for captivate" as to where I should add the .js file. For example should it be in header, or at end of file before closing tag, etc. I know captivate has a loading function for loading the .js files it needs so I wasn't sure if any custom .js files need to come after that? Thank you. Right now I have them load in header. Everything seems to work ok, however I have had some errors when I run it locally with google chrome. It is sporadic so I was thinking it had to do with functions not being available, so that is why I am asking this questions. Thanks in advanced for any insight.
Copy link to clipboard
Copied
Rather than modifying the module's index file, I use the following technique:
To the first page of the module, use "on enter run javascript"
then, use the following to add the external file to the body:
$(‘body’).
append(‘<script src=”/<path to file>/myscript.js” async=”false”></script>’);
this is highly flexible and makes it possible to update the module in captivate without post-processing
Copy link to clipboard
Copied
Thanks, I never thought of that. Would it be a problem if since this is on first page and on reentering the course the user chose to return to where left off and it was a later page say page 5. would that script not get called?
Thanks so much.
Copy link to clipboard
Copied
That is actually a good point! in reality, I add the script to every page. that in itself would work fine and really should load the js file only once regardless of the number of times you add the link. if you are concerned anyway, if you have a function / var that you know is loaded in the file, you can use something like:
if ( typeof your_variable = "undefined" ) {
< set up link >
}
Copy link to clipboard
Copied
See the correct answer in this thread.
Captivate 9 - JavaScript stored in a separate file
This will include the JS file every time project is published.
The folder C:\Program Files\Adobe\Adobe Captivate 9 x64\HTML can only have one index file in it.
So its best to copy and rename the original index file e.g. "index_CP_original.html".
Then make the changes to index.html. i.e. add the line of code that includes the JS script.
When you start a new project it's a good idea to copy and rename index to "index_ProjectName.html".
Then make the new changes to index.html.