• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to Warn the user before closing training session

Explorer ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

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
}
window.addEventListener("beforeunload", leavePage);

 

 

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?

Views

156

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 17, 2020 Sep 17, 2020

Copy link to clipboard

Copied

LATEST

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.

https://youtu.be/sVYONxvt-c4

Paul Wilson, CTDP

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources