473,473 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Mozilla & Mouse coordinates

How can I get the mouse coordinates in Mozilla?

I try
x = event.pageX
but it does not work...
basically I try
alert(event) and it does not work.
Where is the problem?
the full code
------------------------
<script>
var obj = document.getElementById('tooltip');
if (navigator.appName == "Microsoft Internet Explorer") isIE = true; else
isIE = false;

function handlerMM(e){
if (isIE) { x = event.pageX; y = event.pageY; }
else {
alert(event);
x = event.clientX + document.body.scrollLeft;
y = event.clientY + document.body.scrollTop;
}
obj.style.top = y + 10;
obj.style.left = x + 15;
}
</script>
Jul 20 '05 #1
3 10814
<- Chameleon -> wrote:

function handlerMM(e){
if (isIE) { x = event.pageX; y = event.pageY; }
else {
alert(event);
"event" is undefined. An instance of the Event interface is passed as
the argument e.
x = event.clientX + document.body.scrollLeft; x = e.screenX;
y = event.clientY + document.body.scrollTop;
y = e.screenY;
}
obj.style.top = y + 10;
obj.style.left = x + 15;
}


A unit must be concatenated to the length. For example, y + 10 + 'px'

Jul 20 '05 #2
"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> writes:
How can I get the mouse coordinates in Mozilla?
The eight way! (as opposed to how you do it in IE :)
I try
x = event.pageX
but it does not work...
Sure it does, if the variable "event" refers to the event.
In IE, "event" is a global variable that always refer to the
current event, but that is an IE invention, and not all other
browsers have emulated it.
<script>
The type attribute is required in HTML 4.
<script type="text/javascript">
var obj = document.getElementById('tooltip');
if (navigator.appName == "Microsoft Internet Explorer") isIE = true; else
isIE = false;
Browser detection is not a very good way to deduce Javascript
functionality. Partly because browsers change between versions, and
partly because some browsers lie about their name.
function handlerMM(e){
The argument, "e", given to the function when it is called, is the
event.
I usually start my handlers like this:

function handlerMM(event) {
event = event || window.event; // IE sucks!

(yes, I usually write the comment too!).
After this, you can use "event" to refer to the event in all browsers.
if (isIE) { x = event.pageX; y = event.pageY; }
I guess you mean 'if (!isIE)', becuase pageX and pageY are not
available in IE, but are in Mozilla. It would be more prudent to check
for "pageX" directly:

if (typeof event.pageX == "number") {
x = event.pageX;
y = event.pageY; // we dare expect that pageY exists if pageX does :)
} else {
alert(event);
x = event.clientX + document.body.scrollLeft;
y = event.clientY + document.body.scrollTop;
If IE is in standards mode (and it *should* be!), then the html element
is the root of the document tree, not body. In that case, you need to
use document.documentElement instead of document.body.

It's easier jo just use whatever is there, instead of trying to figure
out whethere the page is begins shown according to standards.

var root = document.documentElement || document.body;
x = event.clientX + root.scrollLeft;
y = event.clientY + root.scrollTop;
} obj.style.top = y + 10;
This fails in browsers that follow the standard. CSS lengths must have
a unit, and you are only assigning a pure number.
obj.style.top = (y + 10) + "px";
obj.style.left = x + 15;


ditto.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
Lee
<- Chameleon -> said:

How can I get the mouse coordinates in Mozilla?

I try
x = event.pageX
but it does not work...
basically I try
alert(event) and it does not work.
Where is the problem?
the full code
------------------------
<script>
var obj = document.getElementById('tooltip');
if (navigator.appName == "Microsoft Internet Explorer") isIE = true; else
isIE = false;

function handlerMM(e){
if (isIE) { x = event.pageX; y = event.pageY; }
else {
alert(event);
x = event.clientX + document.body.scrollLeft;
y = event.clientY + document.body.scrollTop;
}
obj.style.top = y + 10;
obj.style.left = x + 15;
}
</script>


In Mozilla and other browsers, the Event object isn't a global
variable. It's an argument that's passed to the event handler.
In your example, it's probably "e".

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cte | last post by:
I have a swing program involving drag and drop - implemented with javax.swing.TransferHandler etc. My problem is that I want to determine the mouse coordinates of a drop onto one of my...
4
by: Jonne | last post by:
Hi, I haven't found anything like this anywhere with Google, so I'm posting it here, hoping one of you people knows how to do something like this. I'm trying to get the mouse coordinates in a div,...
2
by: Robin Senior | last post by:
Hi, I'm trying to drag and drop onto a Panel on my form. The panel is inside a groupBox, which of course is inside my form. When dropping the item onto my Panel, I want it to appear at that...
4
by: Henry Wu | last post by:
Hi, I see examples of Magnifying an area under mouse coordinates to a form or picturebox using VB6 and VC6, does anyone know how to do it under VB.NET? Its nice to use the new GDI+ for it. ...
0
by: Henry C. Wu | last post by:
Hi, I have a form that has a video "inserted" at the form's Handle. Like so: '//Create Capture Window capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100) '// Retrieves driver info lwndC =...
4
by: Luongo | last post by:
Hi, I'm working on a project in which I'd like to have the user's mouse click coordinates included in a php URL which would load onClick, for example http://...imagecreate.php?x=200&y=100. I've...
4
by: atn2002 | last post by:
How can I track the mouse coordinates outside the active window? No one can tell me its not possible because Google Spreadsheets and EditGrid both do it. When you drag down to select cells these...
1
by: Dave | last post by:
I'm running the below script to open a popup window. Works great! How Can I get "Mouse Coordinates" (X,Y) to include them as Left and Top parameters so that the popup window opens "where the...
4
by: mbatestblrock | last post by:
I hope this makes some sense. My ultimate goal here is to execute a block of code if the mouse has not moved in a minute or so within the broswer. The machine I am running this on is for internal...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.