views:

467

answers:

4

hi, i got a web page and when browser fire Closing Event i wanna stop it ? How can i do that in asp.net or anyother alternative?

+8  A: 

You can't, and you shouldn't be able to. How would you feel if StackOverflow were able to prevent you from closing your browser?

Joel Coehoorn
Somehow I think they already do...
Keltex
I can close it- I'm just compelled to re-open it again ;)
Joel Coehoorn
Mine seems to pop-up on its own as part of the build process for every single project I am on. Weird.
Rob Allen
+4  A: 

The answer is simple and is similar to this one:

You can't & you shouldn't.

Whatever your problem is, the solution lies elsewhere.

CJM
+1  A: 

hi you cannot really stop it, but if needed you can warn the user that session informations or whatever will get lost....

<html>
<script type="text/javascript">
var isdone=false
</script>
<body onbeforeunload="if(!isdone) return 'Do you really want to close!';">
</html>
nWorx
A: 

There truly is no way to stop the user from closing the browser.

However, you could potentially write some javascript, which would open up a new window when the user leaves the current page (aka closes the browser, clicks on another link).

This would be a bit annoying to your users, and also would probably be blocked by Pop-Up Blockers.

But it is somewhat possible.

Jack Marchetti