1

I have coding which is working in IE but not in firefox and chrome...

 function handleWindowClose() {
            if ((window.event.clientX < 0) || (window.event.clientY < 0))
             {
                 event.returnValue = "Are You sure to leave this page";
             }
         }
         window.onbeforeunload = handleWindowClose;

Can anyone help me...

user1316760
  • 21
  • 1
  • 1
  • 5

2 Answers2

8

window.event is a IE-only thing. To get it to work in other browsers you have to get the event as an argument of the handler function:

function handleWindowClose(e) {
    e = window.event || e; 
        if ((e.clientX < 0) || (e.clientY < 0))
        {
            e.returnValue = "Are You sure to leave this page";
        }
}
window.onbeforeunload = handleWindowClose;
ccpizza
  • 28,968
  • 18
  • 162
  • 169
1

maybe just add mousemove handler that will store mouse position in variable

var mouse;
function storeMouse(e)
{
    if(!e) e = window.event;
    mouse = {clientX: e.clientX, clientX:e.clientY};
}
function test(e){
     alert(mouse.clientX);
}

and use jquery?

  $(window).bind('beforeunload', function() {
    if (iWantTo) {
        return 'Are You sure to leave this page';
    }
}); 
arpad
  • 541
  • 5
  • 10