Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   HTML, Javascript y otros (https://www.clubdelphi.com/foros/forumdisplay.php?f=38)
-   -   coordenadas actual del mouse? (https://www.clubdelphi.com/foros/showthread.php?t=64735)

gabrielflowers 16-04-2009 14:29:06

coordenadas actual del mouse?
 
hola amigos, tengo una pregunta, como puedo obtener las coordenadas actuales del mouse?
...bueno se que se hace de la sgte manera:
<script language="javascript">
var x=event.clientX;
var y=event.clientY;
alert(x + ' ; ' + y);
</script>...

y funciona bien en explorer y en opera al parecer, mas no funciona en firefox!!!
alguien me puede dar una solucion que sea compatible con firefox (y el resto de navegadores)
gracias, saludos...

winzo 12-11-2009 20:05:29

Respuesta en inglés
 
Ah, I see the problem. You are using Microsoft's Document Object Model. This works in IE 4+, Opera and Konqeuror.
I have modified your code so that it should work in IE DOM friendly browsers and W3C DOM friendly browsers (such as Mozilla, Netscape and Epiphany).
In actual fact you need only use the W3C DOM as this will work in IE 5+, Opera and Konqueor etc anyway, but I've left the IE DOM in case you're catering for IE4 users.
Click anywhere on the page to get the pop up message, move the mouse to lose it.
I don't use Windows so have not tested it in IE but it does work using .all under Konqueror and using getElementById in a variety of browsers.

HTH

<html>
<head>
<title></title>
</head>
<body>
<script language="javascript" type="text/javascript">

document.write("<div id='tip' style='position:absolute;visibility:hidden;left:10 0;top:100'><table borderstyle=outset border=0 bgcolor=#00c00c bordercolor=#ffffff><td id=message><br></td></table></div>");

function tip(msg,myEvent)
{
// check for IE4+ DOM and W3C DOM
scope = document.all? document.all.message : document.getElementById("message");

scope.innerHTML="<font color=#FFFFFF size=2 face=arial>"+msg+"</font>";

// check for IE4+ DOM and W3C DOM
twnd= document.all? document.all.tip : document.getElementById("tip");
twnd.style.visibility="visible";
twnd.style.top=myEvent.clientY+19;
twnd.style.left=myEvent.clientX-2;
}

function hide(){
twnd= document.all? document.all.tip : document.getElementById("tip");
twnd.style.visibility="hidden";
}

</script>
<body onClick="tip('Hello',event)" onMouseMove="hide()">
</body>
</html>


pero funciona!!!!!!


La franja horaria es GMT +2. Ahora son las 16:27:29.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi