Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
how can capture browser close event in asp.net
thnks
Posted

Yes, Griff is right. Here a Tip/Trick in javascript to handle that thing but it has disadvantages(If you refresh that page the same handle will execute[which you want only for browser X close event]) so you decide.

How to detect browser close when browser [X] is clicked?[^]
 
Share this answer
 
Comments
Espen Harlinn 25-Jun-11 12:32pm    
Nice reply, using jQuery makes this nice and simple - my 5
thatraja 25-Jun-11 12:38pm    
Yeah, you can find the solution in jQuery in my Tip/Trick. I don't know jQuery :(
Thank you again Espen
AFAIK, there is no reliable way to do this: It may be possible in Javascript on Firefox (the descriptions I have seen are vague, and seem to be version dependent, using various tricks) but nothing exists that works for all browsers.

And for a good reason. What do you think malicious sites would do with that?

Find another way to do what you are trying that does not involve detecting browser close: it will never be reliable, as the user can just pull teh mains lead out of the back of his PC...
 
Share this answer
 
Comments
Espen Harlinn 25-Jun-11 12:36pm    
Sometimes, when I've put in a decent amount of work on a question here on CP – visiting lots of other sites for reference material, I've been really grateful that we have a feature that tries to prevent me from accidentally closing the browser – when I thought I was closing another browser window :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900