Javascript alerts caused by embedding scorm player in iframe?

Javascript alerts caused by embedding scorm player in iframe?

by Onno Schuit -
Number of replies: 8

I've got a curious problem. If I play a scorm package for the first time, Moodle throws a bunch of javascript alerts (see attached image).

I have embedded the scorm player in an iframe, so I suspect this is the culprit. The exact same scorm package works fine in the regular contexts (either the setting "current window" - without any further iframes - or "new window"). The only difference is that in my Moodle installation I am displaying all Moodle activities in a colorbox popup (so, in an iframe). I've adapted the Grid course format to achieve this (I'm a full time Moodle plugin developer).

So my question is: what should I do to solve or circumvent this problem? Should I hack the scorm package's javascript? Or should I take a look at Moodle's scorm player?


Attachment javascript_alert.png
Average of ratings: -
In reply to Onno Schuit

Re: Javascript alerts caused by embedding scorm player in iframe?

by Onno Schuit -

I've cross posted this issue in a Trivantis forum (here) because I am now convinced that this is caused by the javascript produced by Trivantis / Lectora Online (the authoring software used to produce the scorm package). Or at least that specific javascript code is responsible for the javascript alerts.

Also, the problem does not occur when testing with another (albeit much simpler) scorm package, produced with Adobe Captivate.

In reply to Onno Schuit

Re: Javascript alerts caused by embedding scorm player in iframe?

by Ron Meske -
Picture of Particularly helpful Moodlers


Looks like your course cannot find the SCORM API.  Because of security built into browsers to prevent cross-site scripting, what is in the iFrame cannot interact with what is outside the iFrame.

In reply to Onno Schuit

Re: Javascript alerts caused by embedding scorm player in iframe?

by Onno Schuit -

Turns out that Lectora's trivantis-cookie.js is the culprit. I have added a crude fix by looking for “parent.parent.parent.titlemgrframe”:

function getTitleMgr(A, B) {
    if (!A) {
      return null;
    }
    if (A.jTitleManager) {
      return A.jTitleManager;
    } else if (A.document.titleMgr) {
      return A.document.titleMgr;
    } else {
        var C;
        if (parent.parent.parent) {
          C = eval("parent.parent.parent.titlemgrframe");
        } else if (this.frameElement && this.frameElement.id && this.frameElement.id.indexOf('DLG_content') == 0 && parent.parent) {
          C = eval("parent.parent.titlemgrframe");
        } else {
          C = eval("parent.titlemgrframe");
        }
        try {
            if (!C) C = A.parent.titlemgrframe;
        } catch (e) {};
        if (C) {
            if (C.jTitleManager) return C.jTitleManager;
            else return C.document.TitleMgr;
        } else {
            if (A.name.indexOf('Trivantis_Dlg_') == 0) return getTitleMgr(A.parent, B + 1);
            else {
                if (A.name.indexOf('Trivantis_') == 0) return getTitleMgr(A.opener, B + 1);
                else if (B < 2) return getTitleMgr(A.parent, B + 1);
            }
        }
    };
    return null;
};

Warning: this works in my situation, but if you add yet another nested iframe, you’re going to have to adjust the code.


In reply to Onno Schuit

Re: Javascript alerts caused by embedding scorm player in iframe?

by Mathew Gancarz -
Picture of Core developers

Hi Onno, one thing to be aware of is that everytime it is published out from Lectora, you'll need to drop in the updated javascript code. Easy thing to forget.

In reply to Mathew Gancarz

Re: Javascript alerts caused by embedding scorm player in iframe?

by Onno Schuit -

Hi Mathew,

Yes, unfortunately this adds an extra step to the publishing process for the end users. If they have to do this often enough, I guess I'll have to create a script for them which does this automatically.

In reply to Onno Schuit

Re: Javascript alerts caused by embedding scorm player in iframe?

by Mathew Gancarz -
Picture of Core developers
Actually, looking at your code, since the parent.parent.parent is conditional, you could actually try replacing the javascript file you had tweaked in the Lectora installation folder /Support Files folder with your version. This way it automatically gets pulled in during a publishing. But of course may also break if they try to use the published result in another LMS where parent.parent.parent is true.


Also it would need to be re-updated each time Lectora is patched or installed to a new version to make sure you don't lose it. If you know the people using Lectora will only publish to your LMS variant, it might be less work than the script/manual way of doing it.

In reply to Mathew Gancarz

Re: Javascript alerts caused by embedding scorm player in iframe?

by Onno Schuit -

That's a good one, Mathew, thanks!

In reply to Onno Schuit

Re: Javascript alerts caused by embedding scorm player in iframe?

by Ron Meske -
Picture of Particularly helpful Moodlers


Instead of hard coding the parent.parent.parent...

Why don't you build a recursive function that if the API is not found and there is a parent defined, call itself until the api is found or you are at the top window.  This is how our own scripting works so that we are compatible with all the variations of SCORM API's out there.