473,616 Members | 2,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting co-ordinate position of mouse

5 New Member
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="JavaS cript">
document.onmous emove = getCoordinate;
var mosX = 0 ;
var mosY = 0 ;
function getCoordinate(e )
{
mosX = event.clientX + document.body.s crollLeft ;
mosY = event.clientY + document.body.s crollTop;
document.title = "(X Co-Ordinate » "+ mosX +") ( "+"Y Co-ordinate » " +mosY+")";
document.getEle mentById('dx'). innerHTML = "Mouse X ==» "+mosX+"<br>"+" Mouse Y ==» "+mosY;

return true;
}
</script>
<div id="dX"></div>
</body>
</html>[/HTML]
Sep 15 '08 #1
1 1472
Atli
5,058 Recognized Expert Expert
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
2413
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: ____________ </FORM> <FORM> Search for email: ________________ </FORM>
3
7599
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 end of script headers" for my simple test scripts PHP runs fine from the command line, incidentally I tried changing the doc_root in php.ini from blank to the path of htdocs -- no difference.
4
6013
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 that should have been produced by the defective code), but no error. I have already tried making the following settings in php.ini: display_errors = On
303
17568
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. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
12
1657
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 independent of each other, however, when both are on the page, the "active clock" does not work. I am assuming it is because some of the variables are the same??? Can anyone help please?!?! Here are the 2 scripts: **Active Clock that displays...
19
1844
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 = lst.length; for (var i=0; i < maxItems; i++) {
3
1315
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 which combines a number of tables, each for a specific subject. These have a number of common fields such as 'target'. I want to fnd say the total or average of target for those different subjects. I have all the subject names sitting in an...
3
1740
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 = System.Web.HttpContext.Current.Request.ServerVariables.ToLower();
32
4999
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 not a function" ---------------------------------------------------- I have this in a .js file and in the head section.
32
2004
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=" Set Amplitude " onclick="setAmplitude (this.form)">
0
8199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8145
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7118
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6097
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4140
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.