ASP.NET - Disable The Close Button Of Browser

Asked By Samarth Patel on 03-Nov-10 04:26 AM
Hi

 I  have one application In .net ,

In this User Must clicl on logout for leave the application

For This I want to disable the close button

Suggest me the Solution

Thanks

Samarth

Rohan Dave replied to Samarth Patel on 03-Nov-10 04:32 AM
I believe you can't disable the close button of browser. It's the default behaviour of client browser. We don;t have any control on users machine browser and disable to close button..

definitely you can use some javascript to open up new window and disable the close or maximize, minimize button of window but not in the browser.

You need to clear or close your session once user close the browser...
Jatin Prajapati replied to Samarth Patel on 03-Nov-10 04:33 AM
You can disable the browser's close button but you can run javascript when the browser is being closed and ask the user for the action.. Please refer the below code.

<script language='javascript'>
function onBeforeUnloadAction(){
var flag=window.confirm("You are closing the window. Do you want to log out. Click 'Ok' to close or click 'Cancel' to stay back");

if(flag) { 
//first log out and then close the browser.
} else { 
window.event.cancel = true;
}

}
window.onbeforeunload = function(){if((window.event.clientX<0) || (window.event.clientY<0)){ onBeforeUnloadAction();}
</script>
Sagar P replied to Samarth Patel on 03-Nov-10 04:40 AM
Check this link;

http://www.eggheadcafe.com/community/aspnet/3/53496/how-to-disable-close-button.aspx


http://www.webdeveloper.com/forum/archive/index.php/t-25276.html

http://bytes.com/topic/javascript/answers/430007-disabling-close-button



anil soni replied to Samarth Patel on 03-Nov-10 04:50 AM
You cannot disable the close button.
DL M replied to Samarth Patel on 03-Nov-10 04:55 AM

Try below code sample

FireFox as in MSIE

----------------------


<html><head>

<title>noClose</title>

<script type="text/javascript">

function noClose(){window.history.forward();}

</script>

</head>

<body onload="noClose();" onpageshow="if(event.persisted)noClose();" onunload="">

...blabla...

</body></html>



It works with IE, Firefox, Safari, Opera.

-----------------------------------------------


<script type="text/javascript">

function noClose(){window.history.forward()}

noClose();

window.onload=noClose;

window.onpageshow=function(evt){if(evt.persisted)noClose()}

window.onunload=function(){void(0)}

</script>