Search code examples
javascriptmoodlescorm

Bookmarking LMS, Moodle SCORM


Hi im looking a way to bookmark a page with JavaScript so that when a user reopens a course it remembers the page he or she is on by sending it to SCORM/Moodle.

any ideas folks?

using scorm 1.2 and Moodle 1.9:)

Many Thanks

<!-- ================ -->
<!-- Bookmarking start -->
<!-- ================ -->
<script type="text/javascript" src="SCORM_API_wrapper.js"></script>
<script type="text/javascript">
//Using pipwerks namespace, SCORM 1.2

var success = pipwerks.SCORM.init();

if(success){
  var status = pipwerks.SCORM.get("cmi.core.lesson_status");
  if(status != "completed"){
    success = pipwerks.SCORM.get("cmi.core.lesson_status", "completed");
    if(success){
       pipwerks.SCORM.quit();
    }
  }
}

function setbookMark() {
    var setlessonLocation = scorm.set("cmi.core.lesson_location", "2");
}

function showbookMark() {
    alert(scorm.get("cmi.core.lesson_location"));
}

window.onload = function (){
    init();
    setbookMark();
}


</script>
<!-- ================ -->
<!-- Bookmarking End -->
<!-- ================ -->

First index page that is loaded

<script type="text/javascript" src="SCORM_API_wrapper.js"></script>
<script type="text/javascript">
var scorm = pipwerks.SCORM;


function init(){

    //Specify SCORM 1.2:
    scorm.version = "1.2";

    var callSucceeded = scorm.init();
}

function end(){

    var callSucceeded = scorm.quit();
}


function bookMark() {
    var lessonLocation = scorm.get("cmi.core.lesson_location");
    if (lessonLocation == "1") {
        window.location = "1.html";
        }
    else if(lessonLocation == "2") {
        window.location = "2.html";
        }
    else if(lessonLocation == "3") {
        window.location = "3.html";
        }
    else if(lessonLocation == "4") {
        window.location = "4.html";
        }
    else if(lessonLocation == "5") {
        window.location = "5.html";
        }
    else if(lessonLocation == "6") {
        window.location = "6.html";
        }
    else if(lessonLocation == "") {
        window.location = "1.html";
        }
}

window.onload = function (){
    init();
    bookMark();
}

window.onunload = function (){
    end();
}
</script>

Solution

  • Setting lesson_location is the equivalent of creating a browser cookie... you need to write JavaScript in your course that parses the saved string and makes use of it.

    You need to change your code in a number of places -- the code you've provided is an example that sets your course to complete the instant it's initialized. It isn't really what you're looking for.

    Here's a quick primer on starting the course and looking for a bookmark:

    var bookmark, initialized, status;
    var scorm = pipwerks.SCORM; //shortcut for easier typing
    
    function jumpToPage(url){
    
        //write some code that navigates to the specified url
    
        //Save whatever URL was just used as the bookmark
        //each time the function is invoked.
        scorm.set("cmi.core.lesson_location", url);
    
    }
    
    function init(){
    
        //the default URL in case no bookmark is found
        //or when course is launched for first time
        var url = "url_of_first_page.html";
    
        initialized = scorm.init();
    
        if(!initialized){ alert("Course failed to initialize"); return false; }
    
        //Get the lesson status from the LMS
        status = scorm.get("cmi.core.lesson_status");
    
        if(status === "completed"){
    
            //You're already done, get out of here
            scorm.quit();
            return; //exit init() function
    
        } else if(status === "ab-initio"){
    
            //this is the very first launch, no bookmark will be found in LMS
            //do nothing
    
        } else {
    
            //Check for a bookmark
            bookmark = scorm.get("cmi.core.lesson_location");
    
            //If a bookmark is found, use its value as the target URL
            if(bookmark){ 
                url = bookmark;
            }
    
        }        
    
        jumpToPage(url);
    
    }
    
    
    window.onload = init;