gabrieldoty / simplify-scorm

Scorm 1.2 Javascript API
MIT License
235 stars 77 forks source link

Question: back button api lost connection #40

Open fabmesto opened 3 years ago

fabmesto commented 3 years ago

hi, i would like to understand if my code is correct for start lesson:

<a id="a-apri-lezione" href="javascript:void(0);" onclick="scorm.start(); return false;">
STAART
</a>

<iframe src="" style="border:0px #ffffff none;" id="iframescorm" name="myiFrame" scrolling="no" frameborder="1" marginheight="0px" marginwidth="0px" height="650px" width="100%" type="text/html" allowfullscreen="allowfullscreen" webkitallowfullscreen="webkitallowfullscreen" mozallowfullscreen="mozallowfullscreen"></iframe>

<script src="/scormAPI.js"></script>

<script>
var scorm = {};
scorm.url = 'MY_LESSON_URL';
scorm.student_id = 'MY_ID';
scorm.student_name = 'MY_NAME';

scorm.start = () => {
window.API.cmi.core.student_id = scorm.student_id;
window.API.apiLogLevel = 4;
document.getElementById("iframescorm").setAttribute("src", scorm.url);
}
</script>

This code works, but when user click back button API lost connection with lesson. To restart everything I am forced to refresh browser.

dipakdas99 commented 3 years ago

Hi @fabmesto, What is the scorm URL? Could you please guide me on that? I am assuming you've uploaded an uncompressed zip file in the s3/cloud storage bucket is that right? Thanks in advance!

fabmesto commented 3 years ago

Hi @dipakdas99 Example url here: https://www.netedit.it/scorm/index.html

xob commented 3 years ago

@fabmesto Looking at your example with the Chrome Console open, you can see that when pressing the Back button on the browser, the training gets unloaded and correctly terminates the SCORM API (which it is supposed to do; when a training is unloaded, it should terminate the API). Once the API is terminated, it does not allow being initialized again.

One solution could be to listen to the Terminate event, and call the API's reset function to allow it to be used again. See the Resetting section of the readme.

vivaneo commented 9 months ago

Hi,

I don't know if the repository code still works but I can't do it:

I have the following error:

Uncaught TypeError: Cannot set properties of undefined (setting 'ScormAPI')
     at scormAPI.js:8:33
     at scormAPI.js:691:3

Can you help me ?