can't detect mouse click position in Firefox

Discussion in 'Javascript' started by samuelberthelot@googlemail.com, Jul 7, 2006.

  1. Guest

    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
    , Jul 7, 2006
    #1
    1. Advertising

  2. wrote:
    > 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 ?

    <snip>
    > 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.
    Richard Cornford, Jul 7, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Max
    Replies:
    7
    Views:
    9,076
  2. Wes Harrison
    Replies:
    0
    Views:
    388
    Wes Harrison
    Jun 29, 2006
  3. tom arnall
    Replies:
    6
    Views:
    1,255
    Ian Shef
    Jan 18, 2007
  4. James Black
    Replies:
    0
    Views:
    389
    James Black
    May 28, 2006
  5. Daniish
    Replies:
    2
    Views:
    228
    Thomas 'PointedEars' Lahn
    Jun 13, 2008
Loading...

Share This Page