Forum Moderators: open
can anyone give the solution, here is the code
<HTML>
<HEAD>
<TITLE>Title</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function confirmWindow(){
var msg = "Are you want to close this window";
if((confirm(msg)){
}else{
// i want to keep the window remains open
}
}
function close(){
return false;
}
//-->
</SCRIPT>
</HEAD>
<body onunload="confirmWindow()">
</body>
</HTML>
What you should check out is the
window.onbeforeunloadmethod, any text returned from that function will result in a confirmation window (handled by the browser), and there the user can choose to stay (cancel the action), or go away (close window or navigate away from the page).
[edit]Although the
window.onbeforeunloadis an elegant solution to your problem, but it is not very well supported - if I remember well.[/edit]