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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Internet Explorer - window close 3

Status
Not open for further replies.

nissan240zx

Programmer
Jun 26, 2005
280
US
Hello All,
I am working on a JSP application where I want to capture users' login and logout session information.
My concern is that if the user doesnt use my logout button to end the application, I wont be able to get the value.
What if they close the window by File > Close or just click the "x" or by doing Alt F4.
How do I prevent user from using all these. Can I disable all these close method and only allow endding a session using the logout options in the application.

Please advise
Nissan

A good programmer is someone who looks both ways before crossing a one-way street. - Doug Linder
 
How do I prevent user from using all these.
You can't prevent them from doing this. Consider a dialup user who suddenly looses their connection to the internet (you can't control that they are no longer connected to your web application). Same thing if there is a power loss or their computer is simply switched off (rather than shutdown properly).
Can I disable all these close method and only allow endding a session using the logout options in the application.
Nope. You can't. You'll have to include a "timeout" based on activity or something (or sessions or something) and make the decision that if you have had no activity after the timeout period, to assume the are disconnected and to log them out.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
I have no idea of how to do this JSP but you may be able to hook into the event handler for IE and capture the shutdown event. As Jeff noted this does nothing for you in the event of a shutdown or loss of connection but you would be able to catch a shutdown of IE.

Perhaps the following 2 links will provide a clue:


Ralph Kolva
 
rKolva,
I was looking for some ideas in JavaScript not nessassrily in JSP.
This is an internal applcaiton not for external users so scenarios of power loss and dialup dont exist.

A good programmer is someone who looks both ways before crossing a one-way street. - Doug Linder
 
I have seen on some websites where the "x" is disabled and when you try to close the window it gives a javascript alert box "Do you want to close the window?".
I am looking for some code like that..


A good programmer is someone who looks both ways before crossing a one-way street. - Doug Linder
 
Would this work for you?

<script language="javascript">
window.onbeforeunload=setClose;
</script>

In the setClose function, record the timestamp.
Mark

SELECT * FROM management WHERE clue > 1
> 0 rows returned

--ThinkGeek T-Shrit
 
Hello Kozusnik,
I like this item of using onbeforeunload.
Could you give me an example of how to record the timestamp on setclose.

Thanks
Nissan

A good programmer is someone who looks both ways before crossing a one-way street. - Doug Linder
 
What format are you looking for? yyyy-mm-dd hh:mm:ss

Where are you storing this info? I don't know of a way for javascript to write to a database, not do I know jsp. The only thing I could offer is a php script to handle this. Would that suffice?

Mark

SELECT * FROM management WHERE clue > 1
> 0 rows returned

--ThinkGeek T-Shrit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top