can't detect mouse click position in Firefox

  • Thread starter samuelberthelot
  • Start date
S

samuelberthelot

I've got the following class. the onclick event works only with IE
although I believe I did proper handling for firefox. What is wrong in
this script ?

function PopupDiv(linkId, DivId){
this.Link = getEl(linkId);
this.Div = getEl(DivId);

var me = this;
this.Link.onclick = function Show(event){
var x = 0;
var y = 0;
if (me.Div.style.display == 'none' || me.Div.style.display == ''){
me.Div.style.display = "block";
debugger
if (!event) var e = window.event;
if (e.pageX || e.pageY)
{
x = e.pageX;
alert(x);
y = e.pageY;
}
else if (e.clientX || e.clientY)
{
x = e.clientX;
y = e.clientY;
}
me.Div.style.left = x - 200;
me.Div.style.top = y;

}else{
me.Div.style.display = "none";
}
}
}

thanks
 
R

Richard Cornford

I've got the following class. the onclick event works only with IE
although I believe I did proper handling for firefox. What is wrong in
this script ?
this.Link.onclick = function Show(event){
var x = 0;
var y = 0;
if (me.Div.style.display == 'none' || me.Div.style.display == ''){
me.Div.style.display = "block";
debugger
if (!event) var e = window.event;
if (e.pageX || e.pageY)
<snip>

The - if(!event) - test will be false in Firefox as it passes the event
object to the event handler as an argument. As a result no value will
be assigned to your - e - variable and so - if(e.pageX||e.pageY) - will
error as e is not an object at the point where an attempt is made to
read its 'pageX' property.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top