SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting snapshot of x,y mouse coordinates in Netscape

    Hey guys,

    I've got a little question about finding the mouse location in Netscape. I have a function which is doing a number of things, and at one point needs to capture the x,y location of the mouse. With IE it's no problem:

    x_coord = event.clientX + document.body.scrollLeft;
    y_coord = event.clientY + document.body.scrollTop;

    But with netscape, it seems you need to use the pageX and pageY (are these attributes, functions?) of the event itself - and there doesn't appear to be a generic event object like with 'event' in IE, above. After google-searching, I've found oodles of examples of finding the mouse coordinates by the rather heavy-handed method of overriding the window.onmousemove or window.onmouseclick events like so:

    window.onmousemove = move;

    function move(e) {
    x_coord = e.pageX;
    y_coord = e.pageY;
    }

    but I just want a 'snapshot' of the co-ordinates within my function, without having to override (overload?) an actual event type like onmousemove.

    Any ideas?
    Last edited by AtomicPenguin; Aug 29, 2003 at 00:40.

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I presume you're talking about nn4+. Quick answer (from the quick reply -- no other way.

    What does your function do? And how would assigning the event to a handler affect the rest of your code? (A simple if statement might solve your problem)

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah - the dreaded Netscape 4's and above.

    To be painfully honest, my objections to overriding the event handler are just aesthetic - it doesn't seem neat!

    But it works fine, so what the hey. It's just a simple little script to insert javascript "post-its" into your webpage. I needed a method to find the coordinates of where the user clicked.

    Thanks for your help!

  4. #4
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •