Tuesday, May 30, 2006

To trap the window close event use the onbeforeunload event.

To trap the window close event one can use the onbeforeunload.
This helps to let not leave user before any form is completed.

Works in both IE and Mozilla
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
function unloadMess(){
mess = "Wait! You haven't finished."
return mess;
}
function setBunload(on){
window.onbeforeunload = (on) ? unloadMess : null;
}
setBunload(true);
//-->
</SCRIPT>
</HEAD>
<BODY >
<a href="http://www.microsoft.com" onclick="setBunload(false);">Click here to navigate to
www.microsoft.com</a>
<a href="http://www.microsoft.com" >Click here to navigate to
www.microsoft.com</a>
</BODY>
</HTML>

0 Comments:

Post a Comment

<< Home