I am trying to add a warning to prevent the browser window from being closed before the end of a training session. I've hooked up a beforeunload event handler, setting the event return parameters and return value:
leavePage = function leavePage(evt)
var confirmationMessage = 'Leaving this page your progress will not be saved?';
(evt || window.event).returnValue = confirmationMessage; //IE
(evt || window.event).defaultPrevented = true;
return confirmationMessage; //Chrome
This works as far as being called if the browser close button is clicked, popping up a dialog (chrome ignores the return message, but IE11 includes it). I am testing using SCORM cloud, but in either browser it looks like SCORM cloud also seems to pick up the event, and close the session even if the dialog box "Cancel" is clicked. In actual fact the dialog seems to appear 3 times before disappearing altogether, and allowing the training session to continue, but the SCORM cloud thinks it's finished, and therefore does not report the completion if the user continues to the end of the training.
The response from SCORM Cloud support was:
"What's happening here is that your course has another beforeunload handler elsewhere in its code that calls a cp.UnloadActivities method. This fires before your handler, and tells the SCORM player in Cloud to unload/exit the course. The reason you then see your beforeunload handler fire again after that is because the SCORM player then turns around and tries to close the course popup window when it exits.
Are you using Adobe Captivate to author the course? It looks like that from the file names, and this method seems to be part of its code. I'm not sure if they might have a way for you to implement this that would work better."
I'm therefore coming back here to see if anyone can shed some light on how can I get a warning dialog, that if cancel is selected, continues to run the course to completion?
This isn't exactly what you are looking for but I created this tutorial a few years ago to add an exit confirmation dialogue to an eLearning course. It doesn't warn against closing the browser but gives an intermediate step to using the course exit button.