Featured Categories
-
Lectora®
Lectora® is the most trusted authoring tool in the world. Rock out your creativity! Author courses any way you like. Lectora adheres to best practices for Accessibility and Web Content Accessibility Guidelines (WCAG), offers responsive authoring for eLearning, and publishes to any LMS (Learning Management System).
-
CenarioVR®
Experience virtual reality through CenarioVR®, our training and virtual reality (VR) authoring software that allows you to create immersive learning in minutes! No coding required!
-
Rockstar Learning Platform®
Our Rockstar Learning Platform® has all the features you’ll love. Help your employees be better at their jobs, more valuable to your company, and most effective in servicing your customers.
-
The Training Arcade®
Level up your learner engagement with the Training Arcade®! The Training Arcade is a library of fun, mobile-ready, casual games that can be rapidly customized with your content to create effective gaming!
-
ELB Learning Content
Did you know that our AssetLibrary™ has over 120 million engaging, interactive, and awe-inspiring templates and assets to help you become an eLearning Rockstar®?
Importing a Javascript file at run time

Normally an included JS file is included in a title's html file when the title is compiled (I place it in Header Scripting). It is therefore hard-coded into the title. I would like to avoid this hard-coding.
I would like to be able to include the file at runtime so that the content might be changed in the JS file without the need to re-compile the title. How can I do this? I tried to place <script src="./extern/myscripts.js"></script> in the header scripting section but that did not work - maybe I got the path wrong or maybe..... I may also need to add various bits and pieces to the original .js file to tell the system it is a javascript file.
Any clues would be gratefully received.
Andrew
Comments
-
-
You need to include the script tags with the source attribute. I believe you should be able to keep the external JS file anywhere as long as it is on the same server for security reasons.
The attached example shows that you can replace a lectora variable with a variable from external JS. This is good because you do not have to re-publish to change the variable.
I've asked this before. If a Trivantis application developer see this I would like to know what the thought process is behind the "bottom of file scripting" HTML Extension. Why does it work the way it does? JS script tags belong just above the closing body tag, not after the HTML closing tag as it currently works. Please fix it to follow proper web standards. If there is some other reason for having bottom of file scripting that I am unaware of then please add another option to add links to JS just above the closing body tag - call it "add external JS scripting". -
Thank you Darrel. I will take a close look at your example. I successfully inserted a file as "bottom of file scripting". It appears after the closing html file in the produced file - but I cannot access any of its contents- at least I could not trigger a function.
I agree with your comments to the developers.
-
Hi again Darrel
Wonder what I am doing wrong - maybe you could send the .awt file
The problem I am encountering is that in one or more files, the bottom of script placement is inserting the actual code from the .js file rather than the script tag. It is therefore displaying the content as though it were text and, of course, nothing works. Wonder what I am doing wrong - using Lectora 16 (supposedly patched).
Thanks! -
I think I have partly worked it out. The file reference must be inserted manually as something like <script src="xyz.js"></script> - it must not be a Lectora inserted file - the inserted .js file should not include <script> tags.
I am telling this story so others who may have the same problem might benefit a bit. This works with example files - still not functional in my real files.
-
Darn, I usually have the .awt in my zip. Sorry, it's in this one. The bottom of file scripting must have the script tag and source attribute - <script src="main.js"></script> works.
The actual file you are referencing is just JavaScript, no markup.
I think you have it right above. Any problems let me know. If you want, give me a specific example of what you want to do and I'll code up a sample.
Also keep in mind that you have to manually place the JavaScript file in the published content folder. I should have made that clear as well. Once done, though, you wont have to re-publish to change content in the external JS, just reload.
Darrel -
Thanks Darrel I will look at the example .awt file , but I think I have sorted it out. And yes, you can change the contents of the included file without the need to recompile the whole lesson.
Basically, I am trying to write a Lectora template for use in language learning - and I want inexperienced teachers to be able to produce their own lessons without touching Lectora. This code will help. Thank you so much!
Categories
- 35.9K All Categories
- 110 ✫ Announcements
- 33.2K Lectora®
- 31.1K Lectora Discussions
- 29K Lectora Desktop
- 2K Lectora Online
- 2K Lectora Feature Requests
- 71 Lectora User Groups
- 36 Lectora Accessibility User Group (LAUG)
- 27 ELB Learning Content
- 27 ELB Learning Content Discussions
- 346 CenarioVR®
- 205 CenarioVR Discussions
- 141 CenarioVR Feature Requests
- 44 Rockstar Learning Platform®
- 41 Rockstar Learning Platform Discussions
- 108 CourseMill®
- 108 CourseMill Discussions
- 48 ReviewLink®
- 48 ReviewLink Discussions
- 7 The Training Arcade®
- 7 The Training Arcade Discussions
- 938 All Things eLearning
- 39 eLearning Development
- 546 Learning Management System (LMS) Integration
- 333 Web Accessibility
- 1.2K ♪ The Green Room
- 9 Additional Learning Products