Solved

Catch Cursor position ?

Posted on 2002-05-02
2
162 Views
Last Modified: 2012-08-13
I have couple links on the page.
All links will go to a javascript function that will
alert current cursor x and y position.

How to do that ?
0
Comment
Question by:tanc02
2 Comments
 
LVL 4

Accepted Solution

by:
ckosloski earned 100 total points
ID: 6986539
See if this is what you want.

<html>
<head>
<script>
function ShowMousePosition(event)
{
   if(document.all)
   {
      xpos = event.x;
      ypos = event.y;
   }
   else if(document.layers || (!document.all && document.getElementById))
   {
      xpos = event.pageX;
      ypos = event.pageY;
   }
   alert("x=" + xpos +"\ny=" + ypos);
}
</script>
</head>
<body>
<a href="#" onClick="ShowMousePosition(event);">Link 1</a>
<br><br><br>
<a href="#" onClick="ShowMousePosition(event);">Link 2</a>&nbsp;<a href="#" onClick="ShowMousePosition(event)";>Link 3</a>
</body>
</html>

Corey
0
 
LVL 3

Expert Comment

by:tejaspurani
ID: 6986581
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Simple Ticker</title>
<script language=javascript>
function test(){
     alert(document.body.scrollLeft+event.clientX +"--"+ document.body.scrollLeft+event.clientY);
}
</script>
</head>
<body>
<div style="width:500;height:500;background:yellow;" onclick="test()">

</body></html>

T.P.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question