473,323 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

getting co-ordinate position of mouse

Hello Everybody
i am trying to get co-ordinate position of mouse using java script using the following code.it works fine on IE and other but it is not working on mozilla.i couldn't understand why?please Help me.
My code is like below:-

[HTML]<html>
<body>
<script language="JavaScript">
document.onmousemove = getCoordinate;
var mosX = 0 ;
var mosY = 0 ;
function getCoordinate(e)
{
mosX = event.clientX + document.body.scrollLeft ;
mosY = event.clientY + document.body.scrollTop;
document.title = "(X Co-Ordinate » "+ mosX +") ( "+"Y Co-ordinate » " +mosY+")";
document.getElementById('dx').innerHTML = "Mouse X ==» "+mosX+"<br>"+"Mouse Y ==» "+mosY;

return true;
}
</script>
<div id="dX"></div>
</body>
</html>[/HTML]
Sep 15 '08 #1
1 1457
Atli
5,058 Expert 4TB
That code is only using IE specific code.

You need to check if the standard method is available and only fall back on IE's method if it isn't. Like:
Expand|Select|Wrap|Line Numbers
  1. function getMousePosition(e) {
  2.   pos = [];
  3.  
  4.   if(e) { // Standard method
  5.     pos[0] = e.pageX;
  6.     pos[1] = e.pageY;
  7.   }
  8.   else { // IE specific
  9.     pos[0] = event.clientX + document.body.scrollLeft ;
  10.     pos[1] = event.clientY + document.body.scrollTop;
  11.   }
  12.  
  13.   return pos;
  14. }
  15.  
The if statement checks if the "e" parameter is set.
All standard supporting browsers should pass the even via the e parameter, which contains the mouse cords.
If it isn't set, it falls back on the IE workaround.
Sep 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Wm | last post by:
This is very peculiar -- for some reason, I'm getting 6-8 results from each of these queries, although only one listing matches. I have a pair of forms on one page: <FORM> Search for lastname:...
3
by: Seagull Manager | last post by:
Running Apache 1.3, PHP 4.3, and WinXP, configured acc. to instructions on apache manual and php manual (as far as I can see), but getting "internal server error" in browser... log says "Premature...
4
by: lurisia | last post by:
Hi, I'm not getting any error messages for my incorrect php code, and it's making it very difficult to debug. Instead of an error, the page displays part of the generated html (without the part...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
12
by: Mary Catherine | last post by:
I have 2 scipts that I am trying to get to run on the same page. One is a time/date script, the other is a countdown script (i.e. countdown days, hours, mins until a given date). They both work...
19
by: harry | last post by:
Just want to traverse a listbox's (multi select) items & for those that are selected extract the displayed text - something like below - function getSelectedDescrs(lst) { var buf; var maxItems...
3
by: John M | last post by:
I'm lost on somethingthat I feel ought to be simple - getting the contents of a field! The database relates to school students and their subjects. The current record has as its source a query...
3
by: Adam Tibi | last post by:
Hi, Is there a way of getting the domain name of tghe currently executing site, I tried using this silly code: public static string GetDomainName() { string serverName =...
32
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
32
by: Don Lancaster | last post by:
In an existing, tested and working program, I have a form entry that simplifies to... <INPUT name ="fp1s" type="text" value=0.000 size=12 > and a button of... <input type="button" value="...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.