• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Prevent User to Close the ASP Page from Browser Close Button

Hi,
I have an application desigined in ASP page and I want user to stop from closing the application page from the cross button of the IE. Everytime user click on the IE page it will give the popup message and when user click on it , control will be back to application page.
0
rohit_jha7
Asked:
rohit_jha7
  • 6
  • 5
  • 2
  • +2
11 Solutions
 
CoveyCraigCommented:
Strictly speaking, you cannot disable the close-window button.  However, you can open your window so that the control bar (including the X) are not visible.

window.open('index.aspx','','fullscreen=yes,titlebar=no,toolbar=no,statusbar=no');

0
 
rohit_jha7Author Commented:
No I am not trying to disable the Control Bar including X. What I am trying to findout whenever any user try to close the application page through the IE cross button(X), it will give a popup message to user that he is trying to close the page.
0
 
MrJesse34Commented:
Thats a good solution.  You could also trap the browser "onunload" event and then open a new window, that will also act like the behavior you need.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Wayne BarronCommented:
Here is something for you.
http://ee.cffcs.com/Q_24369336/Q_24369336.html
Click on the [X] to close the page.

Have a good one.
Carrzkiss
<html>
<head>
<title>Detecting browser close in IE</title>
<script type="text/javascript">
var autoRefresh = false;
// Set closure confirmation - Order seems important here.  Must set onbeforeunload first.  Don't know why.
window.onbeforeunload = confirmClose;
// Reload time.  In milliseconds.
window.onload = setTimeout("refresh()", 10000);
 
function refresh() {
    autoRefresh = true;
    window.location.reload(false);
}
 
function confirmClose() {
    if (!autoRefresh) {
        question = "Are you sure...?";
        return question;
    }
}
</script>
</head>
<body >
 
</body>
</html>

Open in new window

0
 
rohit_jha7Author Commented:
It is not working for me because when I put this code on my page it prevent the user from closing the page from the X close and give the popup message but when user select any value from the page and click on submit then also user get the same popup message.

I need to prevent the user from closing the page from the X close and rest of the function will remain same of the page. Something like Windows.event function which tracks the keycode of X close and then give the popup message.
0
 
Anthony PerkinsCommented:
>>I need to prevent the user from closing the page from the X close<<
It cannot be done.  Nor should it be.
0
 
rohit_jha7Author Commented:
Its just not preventing the user but when user clicks on the X close button he will get the custom message and when click on ok then page will close unless if click on cancel then remain on the same page.
0
 
CoveyCraigCommented:
This should do it:


<script type="text/javascript">
	function cw()
	{
		if (window.event.clientX < 0 && window.event.clientY < 0)
		{
			question = "Are you sure...?";
		        return question;
		}
 
	}
</script>
<body onunload="cw()">

Open in new window

0
 
Wayne BarronCommented:
CoveyCraig:
Could not get your code to work?
IE6 | Firefox 3.0.10
0
 
CoveyCraigCommented:
Typo.  The word "onunload" must have a capital U "onUnload"
0
 
CoveyCraigCommented:
Here, this works.  I tested it with IE7.  Make sure you code your hyperlinks as I did and the popup won't occur unless the window is closed.
<html>
	<head>
		<title>"No Close Window"</title>
		<script language="javascript">
			var unloadPop = true;
			function Nav() {
				unloadPop = false;
				window.navigate(arguments[0]);}
			function UnloadTrigger() {
				if (unloadPop) {
alert("Sure you want to leave?");
}
}
window.onunload = UnloadTrigger;
</script>
</head>
<body>
<a href="javascript:Nav('http://www.experts-exchange.com')">Experts Exchange</a>
</body>
</html>

Open in new window

0
 
rohit_jha7Author Commented:
I am unable to prevent the user from closing the page from the X close button. Instead of this if I use this code it will give the prompt message when user tries to navigate from one page to another page.
0
 
Anthony PerkinsCommented:
>>I am unable to prevent the user from closing the page from the X close button.<<
Correct.  I believe I mentioned that previously (#24287754).
0
 
CoveyCraigCommented:
Well, apparently you didn't try the code I provided.  It doesn't PREVENT users from closing using the X button, but it pops up a message.  When you use a hyperlink in the format provided, users do NOT get the message.
0
 
rohit_jha7Author Commented:
No, Issue I have solved the problem by using following code.
<head>
<script language="JavaScript" type="text/javascript">
   function confirmExit()
  {
    if(window.event.clientY < 0)
        {
        event.returnValue = "Please use Logout from the menu";
        alert("You are trying to close the Application which would result in incomplete Handling Time");
   
        }
  }
</script>  
</head>
<body onBeforeUnload="confirmExit()">
</body>
It will first provide the user Alert message and when click on ok, will give option for OK to close the page and cancel to remain on the page
0
 
rohit_jha7Author Commented:
Isse resolved
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now