Powered By Blogger

Search

Thursday, March 13, 2008

Javascript For Catch Browser close Event

Javascript For Catch Browser close Event

Occasionally there is a need to catch browser closing event. The most elegant way to catch browsing closing event in IE is the following short script

< html>
< head>
< title>
< /title>
< /head>
< body onbeforeunload="alert('Closing');">

< /body>
< /html>

Other Way

<script language='javascript'>
function onFeforeUnloadAction(){
var flag;
var mesg ="You are closing the window. \n do you want to continue. Click 'Ok' to close or click \n 'Cancel' to stay back";
return mesg;
}
window.onbeforeunload = function(){if((window.event.clientX<0) (window.event.clientY<0)){ return onBeforeUnloadAction();}
</script>

1 comment:

Tech Shankar said...

Hi. Nanba

Please do not put space between

< and body. It is displaying the text as it is in my browser IE.

I removed space. now it is working.

Thanks