not working both on IE and Mozilla

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sqlexeption
    New Member
    • Feb 2008
    • 2

    not working both on IE and Mozilla

    [CODE=javascript]document.onclic k = getcoordinate;

    var mosX = 0;
    var mosY = 0;

    function getcoordinate(e )
    {
    if (!e) var e = window.event;

    mosX = e.clientX + document.body.s crollLeft;
    mosY = e.clientY + document.body.s crollTop;

    return true;
    }
    [/CODE]
    -----

    <body onclick="getcoo rdinate()">

    -----

    i'm trying this code to get mouse coordinates.

    for 2 days i have read too many forum posts but could not succeed ....

    this code works on IE but in Mozilla it does not work..

    do i miss something?
    Last edited by acoder; Feb 11 '08, 11:48 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    See this link - it should give you an idea about how to get the co-ordinates across all browsers.

    Comment

    • sqlexeption
      New Member
      • Feb 2008
      • 2

      #3
      [CODE=javascript]function doSomething(e) {
      var posx = 0;
      var posy = 0;
      if (!e) var e = window.event;
      if (e.pageX || e.pageY) {
      posx = e.pageX;
      posy = e.pageY;
      }
      else if (e.clientX || e.clientY) {
      posx = e.clientX + document.body.s crollLeft
      + document.docume ntElement.scrol lLeft;
      posy = e.clientY + document.body.s crollTop
      + document.docume ntElement.scrol lTop;
      }
      // posx and posy contain the mouse position relative to the document
      // Do something with this information
      }

      [/CODE]
      the link has this function i change it a little

      [CODE=javascript]var mosX = 0;
      var mosY = 0;

      function getcoordinate(e )
      {
      if (!e) var e = window.event;

      if (e.pageX || e.pageY)
      {
      mosx = e.pageX;
      mosy = e.pageY;
      }
      else if (e.clientX || e.clientY)
      {
      mosx = e.clientX + document.body.s crollLeft
      + document.docume ntElement.scrol lLeft;
      mosy = e.clientY + document.body.s crollTop
      + document.docume ntElement.scrol lTop;
      }
      }[/CODE]

      but it must work but still does not work in mozilla
      and the positons in explorer alittle changed

      is this about mozilla
      Last edited by acoder; Feb 14 '08, 11:25 AM. Reason: Added code tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        JavaScript is case-sensitive: mosx and mosy should be mosX and mosY.

        Comment

        Working...