Solved

Catch Cursor position ?

Posted on 2002-05-02
2
163 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

839 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