473,398 Members | 2,343 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,398 software developers and data experts.

event.offsetX not in IE

Jay
Hi, I'm having a problem getting XY coordinate in my image in firefox and
netscape.

This is only working at IE

function getImageXY(evt1) {
if ('number' == typeof evt.offsetX) { // MSIE
alert("MSIE");
img_x = evt1.offsetX;
img_y = evt1.offsetY;
}
var coordinates = offsetX: ' + offsetX+ ', offsetY: ' +offsetY;
alert (coordinates);
}

I tried to use offsetLeft and offsetTop in firefox and netscape. Whenever I
change viewport(scrolling), it got goofed.
How can I solve this?

Thanks.


--
****************** End of Message ******************
Jul 23 '05 #1
3 8091
Jay wrote:
Hi, I'm having a problem getting XY coordinate in my image in firefox and
netscape.


You will find event coordinates very unreliable across browsers
and even with different doctypes. Read up at quirksmode, I'm
sure you'll find what you are after.

The following page has a reasonably reliable way of getting mouse
coordinates in most browsers:

<URL:http://www.quirksmode.org/js/events_properties.html>
--
Rob
Jul 23 '05 #2
DU
Jay wrote:
Hi, I'm having a problem getting XY coordinate in my image in firefox and
netscape.

This is only working at IE

function getImageXY(evt1) {
if ('number' == typeof evt.offsetX) { // MSIE
evt.offsetX or evt1.offsetX ? There is an error in this code.
alert("MSIE");
Not true. Opera 6+ supports offsetX/Y.
img_x = evt1.offsetX;
img_y = evt1.offsetY;
}
var coordinates = offsetX: ' + offsetX+ ', offsetY: ' +offsetY;
alert (coordinates);
}

I tried to use offsetLeft and offsetTop in firefox and netscape. Whenever I
change viewport(scrolling), it got goofed.
How can I solve this?

Thanks.

Here's a way to get the equivalent of MSIE 5+ event.offsetX/Y properties:

var Element = evt.target ;
var CalculatedTotalOffsetLeft = CalculatedTotalOffsetTop = 0 ;
while (Element.offsetParent)
{
CalculatedTotalOffsetLeft += Element.offsetLeft ;
CalculatedTotalOffsetTop += Element.offsetTop ;
Element = Element.offsetParent ;
};
OffsetXForFirefoxOrNetscape = evt.pageX - CalculatedTotalOffsetLeft ;
OffsetYForFirefoxOrNetscape = evt.pageY - CalculatedTotalOffsetTop ;

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.6 :)
Jul 23 '05 #3
Jay
Thanks a lot, guys!!!

it works now.

Jay
"DU" <dr*******@hotNOSPAMmail.com> wrote in message
news:39*************@uni-berlin.de...
Jay wrote:
Hi, I'm having a problem getting XY coordinate in my image in firefox and netscape.

This is only working at IE

function getImageXY(evt1) {
if ('number' == typeof evt.offsetX) { // MSIE


evt.offsetX or evt1.offsetX ? There is an error in this code.
alert("MSIE");


Not true. Opera 6+ supports offsetX/Y.
img_x = evt1.offsetX;
img_y = evt1.offsetY;
}
var coordinates = offsetX: ' + offsetX+ ', offsetY: ' +offsetY;
alert (coordinates);
}

I tried to use offsetLeft and offsetTop in firefox and netscape. Whenever I change viewport(scrolling), it got goofed.
How can I solve this?

Thanks.

Here's a way to get the equivalent of MSIE 5+ event.offsetX/Y properties:

var Element = evt.target ;
var CalculatedTotalOffsetLeft = CalculatedTotalOffsetTop = 0 ;
while (Element.offsetParent)
{
CalculatedTotalOffsetLeft += Element.offsetLeft ;
CalculatedTotalOffsetTop += Element.offsetTop ;
Element = Element.offsetParent ;
};
OffsetXForFirefoxOrNetscape = evt.pageX - CalculatedTotalOffsetLeft ;
OffsetYForFirefoxOrNetscape = evt.pageY - CalculatedTotalOffsetTop ;

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.6 :)

Jul 23 '05 #4

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

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
3
by: Marcia Gulesian | last post by:
How can I capture the event when I click (focus) with the cursor anywhere in the page (that is, on a component or elsewhere). This event would occur in an I.E 5.5 or later browser.
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
10
by: jjamjatra | last post by:
I am struggling with a event model handling problem in Javascript that shows up only in Firefox. I have 2 little websites I'd like you to take a look at: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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
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,...
0
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...
0
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,...
0
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...

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.