Iframe中的SCORM课程可以'找不到API

SCORM Course in Iframe can't find API

本文关键字:找不到 API 中的 SCORM 程可 Iframe      更新时间:2023-09-26

(我是SCORM和Web开发的新手,如果我没有很好地解释,请原谅。)

我正在尝试运行一些SCORM课程,并一直在遵循本教程:http://www.vsscorm.net/2009/05/31/getting-started-the-rte-frameset/

然而,在本教程中,他们使用框架集和框架来建立从课程到API实现的连接。我需要在iframe中运行我的课程,并且不知道在哪里/如何放置我的API文档,这样我的SCORM课程就可以找到它并连接到它,有人知道怎么做吗?

在典型的SCORM课程中,当课程内容加载到子框架(iframe)中时,API连接在父框架中保持。iframe中的内容可以随意加载和卸载;iframe中的内容往往包含您希望在课程的整个生命周期内进行的重要SCORM调用,例如分数和完成状态,但它们将通过将信息中继到拥有与LMS通信的父框架来实现。

以下是使用SCORM 1.2的快速示例(未在LMS中测试,需要充实)

index.html(父帧)

<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Course Title</title>
    <style>
    /* Use CSS to make the iframe fill the parent frame, 
       giving impression no frames are being used */
    body { padding: 0; margin: 0; overflow: hidden; }
    iframe { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: auto; }
    </style>
  </head>
  <body>
    <iframe src="" id="course-content" frameborder="0"></iframe>
    <script>
    //Place initialization routine here.
    //Connect to SCORM API, run API.LMSInitialize()
    var SCORM_API = window.API; //shortcut reference
    function setScore(score){
      SCORM_API.LMSSetValue("cmi.core.score.raw", score);
    }
    function setStatus(status){
      SCORM_API.LMSSetValue("cmi.core.lesson_status", status);
    }
    function endCourse(){
      SCORM_API.LMSCommit();//Save, just in case
      SCORM_API.LMSFinish();//Close API connection
    }
    SCORM_API.LMSInitialize();
    //Load child frame once SCORM_API is ready
    document.getElementById("course-content").setAttribute("src", "content.html");
    </script>
  </body>
</html>

content.html(子帧)

<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Course Content</title>
  </head>
  <body>
    <p>This is the content of the course. Add scripts to make it do something.</p>
    <script>
    //Place course functionality here, such as setting a bookmark or score.
    //'parent' is the parent frame.
    //This is a very arbitrary example of what you can do when a course loads
    parent.setScore("100");
    parent.setStatus("completed");
    parent.endCourse();
    </script>
  </body>
</html>

您通常希望使用SCORM包装来处理一些繁重的工作,并且希望使用抽象层来提高代码可维护性,并将SCORM命令集中在父框架中。endCourse()函数是抽象层的一个非常简单的例子。不是直接在子框架中调用API,而是调用一个函数。