Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to force Logout on close?

Status
Not open for further replies.

PaulHunt

Programmer
Nov 4, 2005
7
0
0
US
When a user closes a window, or even the browser, I want to log him off. All I can find as hints say to pop a new window using the "onUnload" event, then fire the call to cgi, and close the "popped" window. I can make most, but not all, of that work.
In the popped window, I define a form that has all hidden fields which will submit the closure and logoff info to the cgi program. Then in the <body>, I do onload="window.document.forms['form'].submit();" which fires the cgi if that's all I do. But if I do onload="window.document.forms['form'].submit(); window.close();", then the window closes and the cgi never fires. Adding a delay between the two statements doesn't help.
How can I fire the cgi and then close the window?
Or should I be doing the auto-logoff a different way entirely?
Thanks, Paul
 
You might consider using session cookies - they automatically expire when the user closes their browser, so no need to forcibly log them off at all.

For more details on these, I'd ask in the forum related to whatever server-side technology you are using.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thank you, Dan. I do use cookies, and you're right, they expire either after a certain amount of time or with the end of the session. But they don't expire with the closure of the window, leaving me at least somewhat exposed.

Paul
 
Sorry - I should have said "they can automatically expire when the user closes their browser". This behaviour will depend on what expirty time / date you give the cookie.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
So now I tried the following:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" src='../cshtmlib/js/formHandler.js'></script>
</head>
<body onload = "window.close();">
<form name="form" id="form" method="POST" action="../cgi-bin/CF6005R.PGM">
<input type="hidden" id="Mode" name="Mode" value="CHECK">
<input type="hidden" id="formDone" name="formDone" value="0">
<input type="hidden" id="Request" name="Request" value="CLOSE">
</form>
<script language="JavaScript">
window.document.forms['form'].submit();
</script>
<p>qq</p>
</body>
</html>

And it doesn't fire the cgi unless I leave off the onload = "window.close();".
Yet according to the rules I read, onload doesn't fire until the entire document is loaded and all embedded scripts performed. So why wasn't the submit performed? What am I missing?

Paul
 
Yet according to the rules I read, onload doesn't fire until the entire document is loaded and all embedded scripts performed. So why wasn't the submit performed? What am I missing?

That'll be the rules you read being wrong, then. Where did you read that the onload event does not fire until after all embedded scripts have been performed? I've never heard that one before, and AFAIK, it is very much incorrect.

My belief is that the onload event fires after all content has loaded - whether it has been executed or not.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
> Where did you read that the onload event does not fire until after all embedded scripts have been performed? I've never heard that one before, and AFAIK, it is very much incorrect.

O'Reilly - Javascript, the Definitive Guide - 4th Edition, page 669.
"When the onload event handler is invoked, you can be certain that the document has fully loaded, and therefore that all scripts within the document have executed, .......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top