#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    130
    Rep Power
    14

    Question Mouse x,y coords in Javascript?


    Is there a way to retrieve the x,y coordinates of the mouse in Javascript? I'm not looking for a coodinate stream, just the x,y onclick(). It's going to be my target for a DHTML flyout.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    200
    Rep Power
    14
    If you want to do this in IE:

    http://www.webcoder.com/howto/articl...emo=0,source=0

    If you want to do this in NN:

    No idea. Probably not supported, as usual.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    130
    Rep Power
    14
    Actually, you can do this in both IE and Netscape. The variables are:

    IE:
    window.event.clientX, and windows.event.clientY

    Netscape:
    e.pageX and e.pageY
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    22
    Rep Power
    0
    Actually Void there is a way for NS, and Statik you're missing something.

    <script language="javascript">
    function getMousePos(e) { //you need the 'e', although it does NOT need to be defined
    //NS
    if (document.layers||document.getElementById&&!document.all) {
    alert(e.pageX+"and"+e.pageY)
    }
    //IE
    else if (document.all) {
    form1.X.value=window.event.clientX
    form1.Y.value=window.event.clientY
    }
    }

    if(!window.captureEvents) document.onmousemove=getMousePos
    if (window.captureEvents) {
    window.captureEvents(Event.MOUSEMOVE)
    window.onmousemove=getMousePos //e should not be defined
    }
    </script>
    <body>
    <form name="form1">
    <input name="X" value="">
    <input name="Y" value="">
    </form>
    </body>

    This should do it! In NS you can't use the form, because you can't change the value of the form, for some reason. Hope it helps!
  8. #5
  9. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    function getMousePos(e) {
    //NS
    if (document.layers||document.getElementById&&!document.all) {
    document.form1.X.value = e.pageX
    document.form1.Y.value = e.pageY
    }
    //IE
    else if (document.all) {
    form1.X.value = event.clientX
    form1.Y.value = event.clientY
    }
    }

    Don't call alert()s in a loop!

    Use status as an alternative.

    e is the event object, passed automatically with property assignment (window.onmousemove=getMousePos); if you're calling handlers from HTML, gotta pass it yer own self...Netscape 6 supports pageX & Y properties, but also provides DOM standard clientX & Y as well.
    http://www.brainjar.com/dhtml/events/default4.asp

    cheers,adios
    Last edited by adios; June 25th, 2001 at 11:03 PM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    631
    Rep Power
    14
    *This is Blue Angel*

    LOL, Adios, I didn't know how to access the forms... so all I could think of was to alert it. It's easy to get out of though. Put your mouse at the top of the screen and push enter

IMN logo majestic logo threadwatch logo seochat tools logo