Computing.Net > Forums > Web Development > Confirm close page and logout

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Confirm close page and logout

Reply to Message Icon

Name: MattRobinson
Date: May 26, 2009 at 11:03:32 Pacific
OS: Windows Vista
Subcategory: Javascript/Ajax
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: May 28, 2009 at 05:35:43 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Confirm close page and logout

front page and access www.computing.net/answers/webdevel/front-page-and-access/1136.html

autoscan folder and create links www.computing.net/answers/webdevel/autoscan-folder-and-create-links/1252.html

HELP! Page looks strange in Firefox www.computing.net/answers/webdevel/help-page-looks-strange-in-firefox/1643.html