...

View Full Version : Confirmation on Window Closing Issue



subeeshkk
08-06-2008, 05:35 AM
Hi All,

I am basically new to the web world. I would like to thank you for your time with my question, in advance.

My issue is that, I want a confirmation box before closing my window. I have done this using the event 'onbeforeunload'. It works fine , but the problem is that, the event is been generated when I move to next page or refresh the same page. I want this confirmation only when closing the window.

The code goes like this
***********************
<html>
<head>
<title>Testing</title>
<script language="JavaScript">
<!--
window.onbeforeunload = bunload;

function bunload(){
dontleave="Are you sure you want to leave?";
return dontleave;
}
//-->
</script>
</head>

<body>
Please stay on this page!
</body>


</html>

***********************

Please help me,

Thank You
Subeesh.K.K

IrDewey
08-06-2008, 06:23 AM
it should be:



window.onbeforeunload = bunload();


thats all I can see

dumpfi
08-06-2008, 02:29 PM
@IrDewey: Actually, this line is just fine as is and your "correction" is wrong.

@OP: Try using confirm:

<html>
<head>
<title>Testing</title>
<script language="JavaScript">
<!--
window.onbeforeunload = bunload;

function bunload(){
dontleave=window.confirm("Are you sure you want to leave?");
return (dontleave !== false);
}
//-->
</script>
</head>

<body>
Please stay on this page!
</body>
</html>dumpfi

Kor
08-06-2008, 03:18 PM
the problem is that, the event is been generated when I move to next page or refresh the same page. I want this confirmation only when closing the window.
Impossible with javascript. From the javascript interpreter's point of view all the actions like: navigating to another domain, navigating to another page on the same domain, refreshing, closing the tab, closing the window... all these mean nothing but a single action: closing the session.

A server-side application is able to be a little bit sensitive, as it can make the difference between inner domain (internal session) and outer domain navigation, but that will be all. Nor a server-side application can differentiate between leaving a domain and closing the tab/window/browser.

brusky
12-19-2008, 02:55 PM
I need confirmation only onexit windows but this code dosent let me to submit my form



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum