commit (save) will ensure the LMS actually writes this data to a database.
But what happens if the browser window containing your course is closed by the learner before the course finishes sending data to the LMS? If you’re not careful about how you’ve coded your course, you can lose some of the data. For example, if a learner completes the course and then immediately closes the window, the course might not have had enough time to tell the LMS about the completion, preventing the completion from appearing in the learner’s record.
It’s best to be proactive about this by setting up an event handler for the browser’s
onbeforeunload events. Whatever code you place in these events will execute when the browser is closed. In a SCORM course, you should place a
commit (save) and
terminate (quit) command in these events to ensure the SCORM data is properly persisted in the database and the session is properly terminated.
The code is pretty straightforward (this example uses SCORM 2004):
Since some browsers support
onbeforeunload and others don’t, we use the
unloadHandler on both
onunload, just to be safe. If a browser supports both of these events, the
unloaded boolean ensures the
scorm.quit function is not executed more than once.
If you’re using the pipwerks SCORM wrapper, your code will be even simpler, because the pipwerks wrapper automatically checks the API’s availability before performing any action. The wrapper also sets the
cmi.core.exit parameter for you.
Don’t miss an important piece of what Philip did here, either… He defends against Terminating twice by checking the variable unloaded. A lot of people making use of onunload and onbeforeunload fail to do so, creating API calls against an unloaded API.
Comments are closed.