views:

211

answers:

4

I just ran into a little problem with clientX and clientY.

I put a little event to detect if the mouse goes out of the window and to know where it exits. And there come the trouble, it works fine with firefox, but only sends -1 as an answer in IE. Does someone know if there is a way to solve easily that problem and that without using a framework?

A little bit of code to reproduce that:

<html>
  <head>
    <script type="text/javascript">
 document.onmouseout=function(e){
  if (!e) var e = window.event;
  var relTarg = e.relatedTarget || e.toElement;
  if (!relTarg){
  document.getElementById('result1').innerHTML="e.clientY:"+e.clientY+" e.clientX:"+e.clientX;
  }
 };
    </script>

  </head>
  <body>
 <div id="result1">Not Yet</div>
  </body>
</html>

the results if I exit through the left of the window are:

e.clientY:302 e.clientX:-130 on firefox

e.clientY:-1 e.clientX:-1 on ie.

Thanks in advance.

A: 

Well, either way, doesn't e.clientX < 0 imply the cursor is outside the window?

varzan
Good point.....
Roatin Marth
Hum in fact it's true in IE, but not in firefox, for example if you have a document with a width of 1080px, if you exit through the right of the window, the e.clientX will be someting superior at 1080px. So you can know easily if you exited through bottom/top/left/right this way.In ie you cant cause no matter where you exit, the output is -1/-1
Py
A: 
if(e.pageX)
    {
        _xmouse = e.pageX;
        _ymouse = e.pageY;
    }
    else
    {
        if(typeof(event) == "undefined") return;
        _xmouse = event.clientX + document.body.scrollLeft;
        _ymouse = event.clientY + document.body.scrollTop;
    }

from my project. Think thats what you need

ItzWarty
Hum it seems that it's not what i need, e.page(X|Y) is not defined for ie. On a page w/ no scroll bar it's the same thing as e.client(X|Y)
Py
A: 

Thanks for posting this. It solved my issue. Thanks again

Shefi
A: 

thank you so much

DCCD