Advertisement

01.07.2008 at 01:43PM PST, ID: 23064918
[x]
Attachment Details

e has no properties trying to get the mouse coordinates on an image click

Asked by dds110 in JavaScript

Tags: firefox, netscape, firefox, netscape, javascript window.event, javascript, e has no properties

Hi all,

I'm using the following code to get the mouse coordinates on an image click event.  Works fine in IE, gives the following in NS and FF

e has no properties

here's the code:

function getMouse(e) {
      var posx = 0;
      var posy = 0;
      if (!e) var e = window.event;
      alert(e); //returns undefined
      if (e.pageX || e.pageY)
      {
            posx = e.pageX;
            posy = e.pageY;
      }
      else if (e.clientX || e.clientY)       
      {
            posx = e.clientX + document.body.scrollLeft      + document.documentElement.scrollLeft;
            posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
      }
      
      mouseX = posx;
      mouseY = posy;
      // posx and posy contain the mouse position relative to the document
      // Do something with this information
}

So what am I doing wrong?

ThanksStart Free Trial
[+][-]01.07.2008 at 04:58PM PST, ID: 20604892

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.14.2008 at 06:50PM PST, ID: 20659671

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.21.2008 at 03:23PM PST, ID: 20710641

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.21.2008 at 03:34PM PST, ID: 20710692

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: firefox, netscape, firefox, netscape, javascript window.event, javascript, e has no properties
Sign Up Now!
Solution Provided By: b0lsc0tt
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628