473,387 Members | 3,821 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,387 software developers and data experts.

Mouseposition in Netscape7

Hi everyone!

I've got a little problem and just cann't find any solution for it: I
need to get the current position of the mousecursor at my webpage for
some overlay stuff. Currently I use the following code for this:

if (ieDom)
{
// Internet Explorer
X=window.event.clientX + document.body.scrollLeft;
Y=window.event.clientY + document.body.scrollTop;
}
else if (nsDom)
{
// Netscape 4.xx
X=event.screenX + window.pageXOffset;
Y=event.screenY + window.pageYOffset;
}
else if(W3CDom)
{
// Netscape 6, 7, Mozilla, Opera, etc.
?????????
}

So... can anybody tell me what code to use for the NS6 part? screenX
is redefined in Gecko no longer being the position of the mousecursor
but the position of the browser window.

I would appreciate any help.
Dade
Jul 20 '05 #1
3 1535
da*********@gmx.at (Dade Murphy) writes:
Hi everyone!

I've got a little problem and just cann't find any solution for it: I
need to get the current position of the mousecursor at my webpage for
some overlay stuff. Currently I use the following code for this:

if (ieDom)


Don't switch on what you suspect is the dom. Just og for the
properties themselves. I usually use this:

var root = document.documentElement||document.body;
var pageX = event.pageX || event.clientX + root.scrollLeft;
var pageY = event.pageY || event.clientY + root.scrollTop;

Your code only uses document.body, which fails in IE in standards mode
(and you *should* write new pages to standards mode!).

Both Netscape 4 and Mozilla (and Opera 7) supports "event.pageX",
while IE supports the W3C DOM "clientX" property and the proprietary
"scrollLeft".
/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 #2
Hi again!

Just tried the code you sent. Looks good with NS4 and IE, but still
doesn't work with NS6, NS7 and Mozilla. The mouseposition still
remains unset and the browser gets me some JS exceptions.

Would appreciate further ideas.
Dade

Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<oe**********@hotpop.com>...
da*********@gmx.at (Dade Murphy) writes:
Hi everyone!

I've got a little problem and just cann't find any solution for it: I
need to get the current position of the mousecursor at my webpage for
some overlay stuff. Currently I use the following code for this:

if (ieDom)


Don't switch on what you suspect is the dom. Just og for the
properties themselves. I usually use this:

var root = document.documentElement||document.body;
var pageX = event.pageX || event.clientX + root.scrollLeft;
var pageY = event.pageY || event.clientY + root.scrollTop;

Your code only uses document.body, which fails in IE in standards mode
(and you *should* write new pages to standards mode!).

Both Netscape 4 and Mozilla (and Opera 7) supports "event.pageX",
while IE supports the W3C DOM "clientX" property and the proprietary
"scrollLeft".
/L

Jul 20 '05 #3
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:oe**********@hotpop.com...
da*********@gmx.at (Dade Murphy) writes: <snip> var root = document.documentElement||document.body;
var pageX = event.pageX || event.clientX + root.scrollLeft;
var pageY = event.pageY || event.clientY + root.scrollTop;

Your code only uses document.body, which fails in IE in standards
mode (and you *should* write new pages to standards mode!).
I have mentioned before that your root element determining method is
wrong for IE 5.0 because it has enough of a DOM implementation to have a
documentElement but the root element is _always_ document body.

I don't think that code that needs to choose the root element has much
choice but to either take the line used in the FAQ and see if
documentElement has a non-zero client (or offset) Width/Height prior to
using it, or follow the, IMO better, technique of examining the
document.compatMode property for its existence and content.
Both Netscape 4 and Mozilla (and Opera 7) supports "event.pageX",
while IE supports the W3C DOM "clientX" property and the
proprietary "scrollLeft".


There is a (default) two pixel discrepancy between - event.pageX - and
event.clientX+root.scrollLeft - due to IE including the inner border of
the viewPort in its mouse co-ordinates. It can be corrected for by
subtracting root.clientLeft (and clientTop for Y) from the mouse posting
values (bringing the results into line with the co-ordinates use for
pageX and positioning elements on the page). But because some browsers
do not provide a clientLeft on the root element it would be safer to
default it to zero if undefined. Assuming a browser window size of less
than 2^31 pixels a binary NOT zero operation would be both quick and
safe:-

event.clientX + root.scrollLeft - (root.clientTop|0)

There is also a bug in Opera <= 6 where the clientX/Y values of the
event objects are equivalent to pageX/Y values on other browsers. But
Opera <= 6 does not provide pageX/Y so it has to be arranged that the
scrollLeft/Top and clientLeft/Top are not applied to Opera <=6. This is
the one occasion where I have seen a reason for using the window.opera
property as Opera 7 has PageX/Y so it takes the first option anyway.

Richard.
Jul 20 '05 #4

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

Similar topics

5
by: Krzysztof | last post by:
Hi! I just have a following CSS which works perfect in IE but not in NS7: - #global (and the rest)is not centered in the window - #moj does not position as I expect on the left side of #cont1 ...
7
by: spamfilter | last post by:
Hi, Although I appreciate that Netscape/Firefox implement CSS more according to the rules than MSIE does, I am having a problem getting Netscape etc to display a page as I would like. Have a...
3
by: Asit | last post by:
<META HTTP-EQUIV="expires" content="0"> <META HTTP-EQUIV="pragma" content="no-cache"> <html> <head> <title>Fidelity NetBenefits</title> </head> <body BGCOLOR="#ffffff"> <script...
4
by: Lynn | last post by:
I have been going round in circles trying to get this to work..... I have a form with many fields, each with an onchange() event. There is also an onclick event on the form Submit button. If one...
1
by: Scatropolis | last post by:
How do I set the MousePosition? I found MousePosition but it says it can't modified it because it isn't a variable. thanks
7
by: iwdu15 | last post by:
hi, im trying to egt a picturebox to follow the mousecursor around in a certain area, but the picturebox isnt where the mouse is...how can i get the picturebox to be where the mouse cursor is?...
1
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
When using Control.MousePosition the x values seems to be just fine when I draw something on the screen, but the Y value seems to have got an offset - independently of where on the screen I put the...
2
by: ducttape | last post by:
Hello I'm busy working with an MDI parent and child forms. I've found that there is a discrepancy between the locations returned by DesktopLocation, Control.MousePosition and MouseEventArgs...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...

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.