469,337 Members | 5,924 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,337 developers. It's quick & easy.

window closing event

pshm
20
how to handle window closing event in javascript???

Expand|Select|Wrap|Line Numbers
  1.     window.onunload=function(){    
  2.     if(window.event.clientY < 0 && window.event.clientY < -80){
  3.             alert('window close event triggered');    
  4.         }
  5.     }
this is working bassed on the mouse cursor.. in some case its not working... is there any alternate way to solve this prob??????
Regards,
Prakash M.
Mar 24 '08 #1
12 2351
gits
5,390 Expert Mod 4TB
the unload and onbeforeunload events will always be triggered when you leave the page and they have no corresponding event source ...

is it a popup window or the main browser window where you need a handling?

kind regards
Mar 24 '08 #2
pshm
20
the unload and onbeforeunload events will always be triggered when you leave the page and they have no corresponding event source ...

is it a popup window or the main browser window where you need a handling?

kind regards
hi,
thanks for reply. I need this in main window.
Mar 24 '08 #3
gits
5,390 Expert Mod 4TB
hmm ... in this case you could just use onbeforeunload/onunload to call a js-function to do something when the user navigates away from your page ... there is no real/reliable posibility to capture the close-event of the main window ...

popup windows have a close-property that you might ask for and there you could check for it ...

kind regards
Mar 24 '08 #4
pshm
20
ya i knew for the popup...
in main window closing i need to clear some flags which was set while loading for that only im trying...
Mar 25 '08 #5
gits
5,390 Expert Mod 4TB
ya i knew for the popup...
in main window closing i need to clear some flags which was set while loading for that only im trying...
hi ...

are the flags javascript-variables? aren't they cleared anytime you leave the page?

kind regards
Mar 25 '08 #6
pshm
20
hi,
they are not javascript flags.
the flags belongs to database(SQL server2005).
in my project if any user logged into the system the flag will become true to that corrspond user.this i did in the page_load event.
if the user logged out the flag will be reset to false.
unfortunately if the user close the window without logging out the flages in the DB remains the same.The next time he can't login to the page.
i tried in unload and onbeforeunload for every time the page gets postback these events are getting triggered.
Mar 25 '08 #7
gits
5,390 Expert Mod 4TB
typically you may use a session or a cookie for such purposes. everytime the user performs an action you update a timestamp and when he doesn't do something for a certain amount of time you just log him out and he has to login again ...

kind regards
Mar 25 '08 #8
pshm
20
typically you may use a session or a cookie for such purposes. everytime the user performs an action you update a timestamp and when he doesn't do something for a certain amount of time you just log him out and he has to login again ...

kind regards
ya im using session. by default 20min. if the user doesn't have intraction for 20min the session will be expired, after 20min if he click on some controls it will be redirected to login screen there im clearing the flag in the DB.but the major issue is when he click the close button the session will automatically gets cleared by the browser but the userflag remains same in the DB.
Mar 25 '08 #9
gits
5,390 Expert Mod 4TB
if a user is trying to login why don't you always reset the flag first and clear the session in case he has one? or use a mechanism that resets the flag when there is a 'good' time for it ... may be you retrieve the logged in users sometimes ... with that process reset all userflags where no corresponding session is found ... that could be done for example when the login-page loads?
Mar 25 '08 #10
pshm
20
hi,
do you know about asp.net
in this one event handler is there for handling the application_end event
Expand|Select|Wrap|Line Numbers
  1. void Application_End(object sender, EventArgs e) 
  2.     {
  3.         //  Code that runs on application shutdown     
  4.     }
  5.  
but its not getting triggered properly.
Mar 25 '08 #11
gits
5,390 Expert Mod 4TB
hi,
do you know about asp.net
in this one event handler is there for handling the application_end event
Expand|Select|Wrap|Line Numbers
  1. void Application_End(object sender, EventArgs e) 
  2.     {
  3.         //  Code that runs on application shutdown     
  4.     }
  5.  
but its not getting triggered properly.
unfortunatly i'm not familiar with asp.net ... i would suggest that you would ask the question in the .NET forum ...

kind regards
Mar 25 '08 #12
pshm
20
unfortunatly i'm not familiar with asp.net ... i would suggest that you would ask the question in the .NET forum ...

kind regards
i tried with that only. i didn't get. so that only came to javascript.
ok thank you for spent time to my query

kind regards,
Prakash:)
Mar 25 '08 #13

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

19 posts views Thread by Darren | last post: by
3 posts views Thread by Saradhi | last post: by
2 posts views Thread by RJN | last post: by
2 posts views Thread by chris in grimsby | last post: by
5 posts views Thread by jimmy | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.