Highlighted

Javascript in published SCORM files

Explorer ,
Oct 19, 2019

Copy link to clipboard

Copied

I'm not a guru in javascript, Currently I'm working in a project which someone else was working on it for a long period of time. He prepared some sort of codes in javascript to track number of attempts in SCORM and trigger some battons. I have been given these codes and I don't know where to put them, I'm seeking help to anyone with Javascript knowlege who can assit where to keep these codes in my SCORM files.

 

var interfaceObj;
var eventEmitterObj;
window.addEventListener("moduleReadyEvent", function(evt) {
  //evt.Data carries the interface object.
  //It is same as window.cpAPIInterface
  interfaceObj = evt.Data;
  eventEmitterObj = interfaceObj.getEventEmitter();
  //check if window.cpAPIInterface is available
  if (interfaceObj) {
    //check if window.cpAPIEventEmitter is available
    if (eventEmitterObj) {
.
.
.
.
});

 

Topics

Quizzing and LMS

Views

163

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

Javascript in published SCORM files

Explorer ,
Oct 19, 2019

Copy link to clipboard

Copied

I'm not a guru in javascript, Currently I'm working in a project which someone else was working on it for a long period of time. He prepared some sort of codes in javascript to track number of attempts in SCORM and trigger some battons. I have been given these codes and I don't know where to put them, I'm seeking help to anyone with Javascript knowlege who can assit where to keep these codes in my SCORM files.

 

var interfaceObj;
var eventEmitterObj;
window.addEventListener("moduleReadyEvent", function(evt) {
  //evt.Data carries the interface object.
  //It is same as window.cpAPIInterface
  interfaceObj = evt.Data;
  eventEmitterObj = interfaceObj.getEventEmitter();
  //check if window.cpAPIInterface is available
  if (interfaceObj) {
    //check if window.cpAPIEventEmitter is available
    if (eventEmitterObj) {
.
.
.
.
});

 

Topics

Quizzing and LMS

Views

164

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
New Here ,
Oct 20, 2019

Copy link to clipboard

Copied

The basic answer would be to place the Javascript shown on the first slide of your project.

  1. Open Actions on the first slide of your project
  2. Under the On Enter action select Esecute Javascript
  3. Click on Script_Window
  4. Cut & Paste the Javascript into the widow and Click OK

You can't preview javascript unless you are in a browser. You won't be able to test your SCORM code unless you are in an LMS. I like to test SCORM code in SCORM Cloud https://rusticisoftware.com/products/scorm-cloud/

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...
Advocate ,
Oct 21, 2019

Copy link to clipboard

Copied

Perhaps some things have changed, but my experience has been that the Execute JavaScript window does not permit comments.

 

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...
Most Valuable Participant ,
Oct 21, 2019

Copy link to clipboard

Copied

No Greg, that has not changed at all. Didn't want to insult the user who answered yesterday. It is clear that this script needs to be in an external JS file, not inserted in the script window in CP.

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...
New Here ,
Oct 21, 2019

Copy link to clipboard

Copied

I don't know where this broke but I've used javascript comments in the Script_Window successfully in the past. Testing today with the latest CP shows that single line comments break the script but multi-line comments don't. 

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...
New Here ,
Oct 21, 2019

Copy link to clipboard

Copied

Looking further at this I can confirm that single line comments in javascript worked (and still do) in CP 2017 (10.0.1.285).  Do you know what version this broke in?

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...
Advocate ,
Oct 22, 2019

Copy link to clipboard

Copied

I do not.

All I know is that at some point when I started using the 'Execute JavaScript' window - I started with some comments and it would not work until I took them out.

I never bothered to try again.

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...
Resources
Captivate User Guide
New Group