Is there any way to capture the user closing the browser window?

Dec 21, 2015

I'm saving out some variables when the user closes my course, so I want them to use my "Save & Exit" button instead of closing the browser window.

Is there a way I can capture the closing of the browser window, without having to manually edit any of the course files after publishing?

Thanks,

Mike

 

4 Replies
Phil Mayor

could you add something like this to your html page?

This won't prevent them exiting, which really you should not be able to do, but you could customise the message to say exiting this way may mean you lose your work. Probably a good way to annoy a user though.

window.onbeforeunload = confirmExit;
function confirmExit() {
return "You have attempted to leave this page. Are you sure?";
Mike B.

This works pretty well. I had to also add the code to my "Save & Exit" page, and tell it NOT to display the message, as it's a little annoying to see when the user actually clicks my Exit Course button. I'm not sure why the code was executing there when I had placed it on another slide (no longer on the slide master).

Also, in Firefox, a default message is displayed instead of the one specified in the js code, which isn't the end of the world.

This discussion is closed. You can start a new discussion or contact Articulate Support.