0

I have a published captivate html file that is loaded into an iframe of another html. I cannot communicate between the two, not even with localStorage. Can anyone tell me what I'm missing?

Parent html

    var everythingLoaded = setInterval(function () {
            if (/loaded|complete/.test(document.readyState)) {
                clearInterval(everythingLoaded);
                init();
            }
        }, 10);

        function init() {

            ScormProcessInitialize();
            var studentID = ScormProcessGetValue("cmi.core.student_id");
            var student_name = ScormProcessGetValue    ("cmi.core.student_name");
            var nameArraya = student_name.split(" ");
            var nameArrayb = nameArraya[1].split(",");
            var studentNumber = nameArrayb[0];
            ScormProcessSetValue("cmi.core.lesson_status", "incomplete");
            localStorage.setItem("_studentNumber", studentNumber);
            alert("Student Number: " + studentNumber + "  Student Mame: " + student_name);
            setTimeout(function () {
                  document.getElementById("iFrame_a").innerHTML = "<iframe name='iframe_1' id='frame_1' src='//somepath.com/sandbox/somecourse/index.html' frameborder='0' width='1000px' height='605px'></iframe>";
            }, 250);
        }

        function sendComplete() {
            alert("Send from index start!");
            ScormProcessSetValue("cmi.core.lesson_status", "completed");
            alert("send status: Completed");
        }
        window.onbeforeunload = function (){

            cpInfoCurrentSlide = localStorage.getItem("_cpInfoCurrentSlide")
            alert(cpInfoCurrentSlide);
            if(cpInfoCurrentSlide >= 40)
                {
            alert("onbeforeunload called: " + cpInfoCurrentSlide )
            ScormProcessSetValue("cmi.core.lesson_status", "completed");
                }
        }

iframe code snippet

localStorage.setItem("_cpInfoCurrentSlide", cpInfoCurrentSlide);
Tinman
  • 31
  • 7
  • is the url of the iframe the same domain and subdomain as the parent frame? also is the captivate file exported as SCORM 1.2 or SCORM 2004, or some other package format? – acolchagoff May 10 '17 at 18:38
  • can you post the code from some of your failed attempts? – acolchagoff May 10 '17 at 19:15
  • also if I remember correctly if captivate is unable to communicate with the scorm api on the parent frame you will get an error message indicating a problem. are you getting this error? – acolchagoff May 10 '17 at 19:16
  • I'm handling the SCORM tracking from the parent page via a SCROM library, there is no SCORM tracking in the Captivate published files. Also no SWF just html. The files are not an the same domain. There is a cross-domain xml in place. – Tinman May 10 '17 at 19:17
  • There is no error. The scorm is working fine. I just need to get current frame number from the captivate html to the parent html to know when to submit the completion to the lms. I get a null value from the localStorage object when I call for it. It is being set, I can see that from an alert on the cap html. – Tinman May 10 '17 at 19:18
  • sounds like a typical parent to iframe communication, but I need to see your code to know what you're doing wrong. can you post it? – acolchagoff May 10 '17 at 19:20
  • does your scorm library have hooks? Captivate probably isn't going to have a nice clean way to get the frame number, but perhaps you could listen for it's call to API.LMSCommit() (in scrom 1.2) and then run your code then. if cmi.completion_status == 'complete' you're good. – acolchagoff May 10 '17 at 19:24
  • also, what LMS are you using? – acolchagoff May 10 '17 at 19:26
  • In the captivate html the var cpInfoCurrentSlide gets the current slide number, that's working fine. – Tinman May 10 '17 at 19:40
  • I need more context, is this code from the parent frame or the iframe? did you combine two different blocks of code? If so, please post them as separate blocks instead. – acolchagoff May 10 '17 at 19:43

1 Answers1

0

I believe your problem is with onbeforeunload. As I remember captivate packages clobber any functions associated with onbeforeunload in the parent frame when they load.

Try this instead, override your SCORM api setvalue method:

var oldLMSSetValue = window.API.LMSSetValue;
window.API.LMSSetValue = function(key, value){
  if(key === 'cmi.core.lesson_status' && value === 'completed'){
    //do your stuff here
    cpInfoCurrentSlide = localStorage.getItem("_cpInfoCurrentSlide")
    alert(cpInfoCurrentSlide);
  }
  //call the original scorm api function so that it runs as expected.
  oldLMSSetValue(key,value);
};

edit: this code would go in the parent window, not the iframe.

acolchagoff
  • 1,926
  • 3
  • 18
  • 30