Highlighted

How to Warn the user before closing training session?

Explorer ,
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

35

Likes

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

How to Warn the user before closing training session?

Explorer ,
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

36

Likes

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
Aug 11, 2020 0
Adobe Community Professional ,
Aug 11, 2020

Copy link to clipboard

Copied

Try using this for the prevent default:

 

(evt || window.event).preventDefault();

Likes

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
Reply
Loading...
Aug 11, 2020 0
Explorer ,
Aug 11, 2020

Copy link to clipboard

Copied

I tried that before (and again!), but it doesn't make any difference, the training session still closes even if the leave dialog is cancelled.

Likes

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
Reply
Loading...
Aug 11, 2020 0
Adobe Community Professional ,
Aug 12, 2020

Copy link to clipboard

Copied

It would take quite a bit of work to change Captivates unload handlers and it would need to be done manually each time ou publish.

 

It may be able to be done in the scormdriver.js if you triggered a variable along with CP's exit command. Don't have time to research that, but may be an option.

Likes

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
Reply
Loading...
Aug 12, 2020 0