Confirm close page and logout

May 26, 2009 at 11:03:32
Specs: Windows Vista
So here's the situation: I have a web based program that allows a user to log in, take a test, etc. To prevent a user from accidentally exiting out of a test before they are done, I am using the onbeforeunload event that brings up the popup to allow a user to confirm to navigate away from the page. i.e.

<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
function establishUnloadGuard(){ = unloadMess;
function unloadMess(){
mess = "This will finish your test attempt.";
return mess;

The problem is that when they do close the test in this manner, it needs to be recorded in the event log. So I have come up with 2 possible solutions, but I don't know how to implement them (or if they are even feasible). One, create my own popup similar to the one provided by the browser and find out the user response that way, or two, somehow regain control before the page closes and log the event. Any help would be great!


See More: Confirm close page and logout

Report •

May 28, 2009 at 05:35:43
If it's a form full of test questions and user info, then you can *probably* use ajax to post the form during your unloadMess function if the user elects to "save" or whatever your options are.

If it's just notification that a user quits or whatnot, then you could *probably* get away with creating a query string during your unloadMess function. window.location = url + "?act=cancel" or such.

Either way, javascript isn't going to be of much use alone, you'll need some form of server side scripting to process whichever result is given.

Report •
Related Solutions

Ask Question