Solved

Catch Cursor position ?

Posted on 2002-05-02
2
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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. …
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

738 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