Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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(){
window.top.onbeforeunload = unloadMess;
}
function unloadMess(){
mess = "This will finish your test attempt.";
return mess;
}
</SCRIPT>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!
Matt

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.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |