Hi, Even I am trying the browser close event for cross browser and this should trigger only when X button is clicked or page is refreshed. Here's the code pasted above which I am using but it only works in IE. I know the issue is because of window.events and ClientX/ClientY. Could someone please fix my code to make it work in all browsers? This is very urgent and have been striving since 3 days...
*Please Note: Current code is working in IE only and to check you have to close the browser window or refresh the page with mouse click
===================== <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><head> <title>Warning Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script language="JavaScript"> // warning message javascript var isOpera, isIE, isNav, isFox, isOther = false; if (navigator.userAgent.indexOf("Opera") != -1) { isOpera = true; } else if (navigator.userAgent.indexOf("Firefox") != -1) { isFox = true; } else if (navigator.appName == "Microsoft Internet Explorer") { isIE = true; } else if (navigator.appName == "Netscape") { isNav = true; } else { isOther = true; } if (isIE || isOpera || isNav || isFox || isOther) { window.onbeforeunload = WarnUser; function WarnUser() { OffsetX = window.event.clientX; OffsetY = window.event.clientY; if (((window.event.clientX < 0) || (window.event.clientY < 0)) && (isWarnUser == true)) { event.returnValue = " "; //window. önunload = sessionInvalidate; } else { // Reset the flag to its default value. isWarnUser = true; } } } </script> </head> <body> <script type="text/javascript"> var isWarnUser = true; </script> test </body> </html> ========================
ok, first of all i am not really sure what you want to do, but there is a event that occurs when you close the window.. and that is:
<BODY onUnload="function()"> if you want to check if the F5 button on the keyboard is pressed try something like:
document.onkeydown=keyaction;
function keyaction(e)
{
if(!e)e = window.event;
alert(e.keyCode);
switch(e.keyCode)
{
case 63:function()
}
}
i don;t remember what is the code for F5, try that code and check it out...
if you want to occur only if the X or refresh button is press, i don;t know how to do that...
another thing that you should know is that such a event when you are closing the window/site is annoying sometimes, at least the one you put in the test