2017-05-10 12 views
0

別のhtmlのiframeに読み込まれた、公開されたcaptivate htmlファイルがあります。私は2つの間で通信することはできませんが、localStorageでは通信できません。私が何が欠けているか教えてもらえますか?captivate htmlと親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コードスニペット

localStorage.setItem("_cpInfoCurrentSlide", cpInfoCurrentSlide); 
+0

iframeの親フレームと同じドメインとサブドメインのURLですか? SCORM 1.2またはSCORM 2004としてエクスポートされたキャプティブファイル、または他のパッケージ形式もありますか? – denodster

+0

いくつかの失敗した試行のコードを投稿できますか? – denodster

+0

また、Captivateが親フレームのscorm apiと通信できない場合、問題があることを示すエラーメッセージが表示されます。このエラーが出ていますか? – denodster

答えて

0

親HTML私はあなたの問題はonbeforeunloadであると信じています。私が覚えているように、パッケージがロードされると、親フレーム内の前回のロードに関連するすべての機能を取り除きます。

あなたのSCORM APIのSetValueメソッドをオーバーライドし、代わりにこれを試してみてください:

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); 
}; 

編集を:このコードは、親ウィンドウではなく、iframe内に行くだろう。

関連する問題