How to show confirm message on window close?

Posted by Satyadnet under ASP.NET on 4/24/2009 | Views : 9445 | Status : [Member] | Replies : 3
Hi all,
I have one requirement, while i am closing window i need to show confirm message, if user click cancel i don't want close that window.

Advance thanks.




Responses

Posted by: Majith on: 4/24/2009 [Member] Starter

Up
0
Down
Satya,

Add the following javascript on your page to dispaly alert message while close the page or to navigate to other page.


<script type="text/javascript">
window.onbeforeunload = function (evt) {
var reply= "";
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = reply;
}
return reply;
}
</script>


Satyadnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyadnet on: 4/24/2009 [Member] Starter

Up
0
Down
Thank you Mr Majith, It is working fine . But i want when i close the page only not navigating .


Satyadnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakhangarg on: 8/31/2009 [Member] [Moderator] Silver

Up
0
Down
Hi-

Body unload Event

onunload=return confirm ('Do you want to close window?');

Thanks & Regards
Lakhan Pal Garg
http://lakhangarg.blogspot.com/


Satyadnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response