www.webdeveloper.com
Results 1 to 4 of 4

Thread: Set the mouse position...

  1. #1
    Join Date
    Jul 2004
    Location
    Mauritius
    Posts
    1

    Set the mouse position...

    Hi,

    I want to set the mouse position in my webpage with the following code (IE version) :

    PHP Code:
    event.0
    but it doesn't work (script error). I saw in the MSDN doc that properties 'x' and 'y' enable to set or retrieve the mouse position.

    Does someone know a tip to help me ?

    Thanks for any answer...
    Last edited by David.V; 07-09-2004 at 06:44 AM.

  2. #2
    Join Date
    Nov 2002
    Posts
    4,473
    You cannot move the mouse. The x and y represent where the mouse was when the event occurred. You can write to those values, but it will not move the mouse.

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Here's a cross-browsers solution:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    script>
    function 
    checkS(e){
    // capture the mouse position
        
    var posx 0;
        var 
    posy 0;
        if (!
    e) var window.event;
        if (
    e.pageX || e.pageY)
        {
            
    posx e.pageX;
            
    posy e.pageY;
        }
        else if (
    e.clientX || e.clientY)
        {
            
    posx e.clientX
            
    posy e.clientY
        }
    document.getElementById('pos').innerHTML 'Mouse position is: X='+posx+' Y='+posy;
    }
    </script>
    </head>

    <body onmousemove="checkS(event)">
    <div id="pos"></div>
    </body>
    </html> 

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    eeerr, yes... you wrote set, I was not attentive and understood get the mouse position. gil davis may be right, I think you may not move the mouse...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles