<HTML>
<head>
<script>
function closeIt()
{
return "Any string value here forces a dialog box to \n" +
"appear before closing the window.";
}
window.onbeforeunload = closeIt;
</script>
</head>
<body>
<a href="http://www.microsoft.com">Click here to navigate to
www.microsoft.com</a>
</body>
</html>
Your marked answers helps other fixing fast...
Cheers!
Tarun Juneja
http://meghainfotech.wordpress.com/
<html>
<head>
<title>Detecting browser close in IE</title>
<script type="text/javascript">
var message="If you have made any changes to the fields without clicking the Save button, your changes will be lost.";
function ConfirmClose(e)
{
var evtobj=window.event? event : e;
if(evtobj == e)
{
if (!evtobj.clientY)
{
evtobj.returnValue = message;
}
}
else
{
//IE
if (evtobj.clientY < 0)
{
evtobj.returnValue = message;
}
}
}
</script>
</head>
<body onbeforeunload="ConfirmClose(event)">
<h4>Close browser!</h4>
</body>
</html>
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Nirmal kumar...
Member
26 Points
33 Posts
How to restrict the user to close window button in a browser?
May 22, 2012 05:50 AM|LINK
Booking ticket contains four steps to finish, they are One.aspx -> two.aspx -> three.aspx -> four.aspx
My question is,
let us assume you are in the three.aspx,
Now you are trying to close the windows that time
One pop up should come and warn the user (do not close it)
till you reaching four.aspx
Do you have any idea to achieve the same?
ItsSunny
Contributor
2163 Points
676 Posts
Re: How to restrict the user to close window button in a browser?
May 22, 2012 06:03 AM|LINK
Check this
http://viralpatel.net/blogs/2008/12/how-to-capture-browser-close-button-event-or-exiting-the-page-in-javascript.html
http://forums.asp.net/t/1153888.aspx
Arun Sunny.
tarun n june...
Contributor
4054 Points
902 Posts
Re: How to restrict the user to close window button in a browser?
May 22, 2012 06:07 AM|LINK
You need to do it on onbeforeunload event
Here is the working link of below example
http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onbeforeunload.htm
Here is the code for same
<HTML> <head> <script> function closeIt() { return "Any string value here forces a dialog box to \n" + "appear before closing the window."; } window.onbeforeunload = closeIt; </script> </head> <body> <a href="http://www.microsoft.com">Click here to navigate to www.microsoft.com</a> </body> </html>Cheers!
Tarun Juneja
http://meghainfotech.wordpress.com/
nitinihi
Member
164 Points
45 Posts
Re: How to restrict the user to close window button in a browser?
May 22, 2012 06:43 AM|LINK
show popup on page unload event.
Nitin Kumar
mark as answer if helpfull
Song-Tian - ...
All-Star
43715 Points
4304 Posts
Microsoft
Re: How to restrict the user to close window button in a browser?
May 23, 2012 05:38 AM|LINK
Hi,
Please refer to the code as follow:
<html> <head> <title>Detecting browser close in IE</title> <script type="text/javascript"> var message="If you have made any changes to the fields without clicking the Save button, your changes will be lost."; function ConfirmClose(e) { var evtobj=window.event? event : e; if(evtobj == e) { if (!evtobj.clientY) { evtobj.returnValue = message; } } else { //IE if (evtobj.clientY < 0) { evtobj.returnValue = message; } } } </script> </head> <body onbeforeunload="ConfirmClose(event)"> <h4>Close browser!</h4> </body> </html>Feedback to us
Develop and promote your apps in Windows Store