473,770 Members | 6,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get X,Y coord's like "ismap" ?

For use in IE only:

I need to make some calculations (in a client-side script) based on
the X,Y coordinates of the mouse pointer when the user clicks on an
image. I want the coordinates to be screen-resolution independent.

The image tag's "ismap" generates exactly the numbers I'm looking for
but I can't figure out how to capture them. "ismap" seems to work only
when used in conjunction with an "href" and a new page is
automatically requested. Is there a way to grab those numbers without
requesting a new page?

Alternatively, can someone tell me how to generate the equivalent
numbers?

I've tried looking at just about every X and Y related property on the
"image" and "event" objects but I can't seem to duplicate the "ismap"
numbers.

Any thoughts?

Thanks
Jul 23 '05 #1
9 3519
Martin wrote on 21 aug 2004 in comp.lang.javas cript:
For use in IE only:

I need to make some calculations (in a client-side script) based on
the X,Y coordinates of the mouse pointer when the user clicks on an
image. I want the coordinates to be screen-resolution independent.

The image tag's "ismap" generates exactly the numbers I'm looking for
but I can't figure out how to capture them. "ismap" seems to work only
when used in conjunction with an "href" and a new page is
automatically requested. Is there a way to grab those numbers without
requesting a new page?

Alternatively, can someone tell me how to generate the equivalent
numbers?

I've tried looking at just about every X and Y related property on the
"image" and "event" objects but I can't seem to duplicate the "ismap"
numbers.


Googling gives many examples:

<html>
<script type="text/JavaScript">
document.onmous emove = doit;
function doit() {
X = event.x + document.body.s crollLeft - 2;
Y = event.y + document.body.s crollTop - 2;
window.status=
"Coordinate s of the pointer: x = " + X + " ; y = " + Y;
}
</script>
Mouse coordinates are shown on the statusbar.
</html>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2
On 21 Aug 2004 22:13:09 GMT, "Evertjan."
<ex************ **@interxnl.net > wrote:
Googling gives many examples:

<html>
<script type="text/JavaScript">
document.onmou semove = doit;
function doit() {
X = event.x + document.body.s crollLeft - 2;
Y = event.y + document.body.s crollTop - 2;
window.status=
"Coordinate s of the pointer: x = " + X + " ; y = " + Y;
}
</script>
Mouse coordinates are shown on the statusbar.
</html>


Thanks for the reply. In fact, I'm already using that code for some
other purposes.

But it does not yield the numbers I'm looking for; it returns the
mouse pointer's screen coordinates. And, the actual numbers returned
are dependent on the screen resolution.

I'm looking for something that tells me where the pointer is <in the
image> AND, will return the same values no matter what the display
resolution is.

Any other thoughts?
Jul 23 '05 #3
On Sat, 21 Aug 2004 15:36:01 -0700, Martin <ma**********@c omcast.net>
wrote:
On 21 Aug 2004 22:13:09 GMT, "Evertjan."
<ex*********** ***@interxnl.ne t> wrote:
Googling gives many examples:

<html>
<script type="text/JavaScript">
document.onmo usemove = doit;
function doit() {
X = event.x + document.body.s crollLeft - 2;
Y = event.y + document.body.s crollTop - 2;
window.status=
"Coordinate s of the pointer: x = " + X + " ; y = " + Y;
}
</script>
Mouse coordinates are shown on the statusbar.
</html>


Thanks for the reply. In fact, I'm already using that code for some
other purposes.

But it does not yield the numbers I'm looking for; it returns the
mouse pointer's screen coordinates. And, the actual numbers returned
are dependent on the screen resolution.

I'm looking for something that tells me where the pointer is <in the
image> AND, will return the same values no matter what the display
resolution is.

Any other thoughts?


Oops...

Pardon me for a moment while I pull my head out of my ass. :(

I went back and took another look at function I had (that you
provided) and found that it does, in fact, provide the same numbers at
differing resolutions. What I was failing to do was to properly
account for the offsets (to the centered image) that are generated at
different resolutions. When I calculate things correctly, I get the
numbers I wanted.
Jul 23 '05 #4
On Sat, 21 Aug 2004 16:07:40 -0700, Martin <ma**********@c omcast.net>
wrote:
On Sat, 21 Aug 2004 15:36:01 -0700, Martin <ma**********@c omcast.net>
wrote:
On 21 Aug 2004 22:13:09 GMT, "Evertjan."
<ex********** ****@interxnl.n et> wrote:
Googling gives many examples:

<html>
<script type="text/JavaScript">
document.onm ousemove = doit;
function doit() {
X = event.x + document.body.s crollLeft - 2;
Y = event.y + document.body.s crollTop - 2;
window.status=
"Coordinate s of the pointer: x = " + X + " ; y = " + Y;
}
</script>
Mouse coordinates are shown on the statusbar.
</html>


Thanks for the reply. In fact, I'm already using that code for some
other purposes.

But it does not yield the numbers I'm looking for; it returns the
mouse pointer's screen coordinates. And, the actual numbers returned
are dependent on the screen resolution.

I'm looking for something that tells me where the pointer is <in the
image> AND, will return the same values no matter what the display
resolution is.

Any other thoughts?


Oops...

Pardon me for a moment while I pull my head out of my ass. :(

I went back and took another look at function I had (that you
provided) and found that it does, in fact, provide the same numbers at
differing resolutions. What I was failing to do was to properly
account for the offsets (to the centered image) that are generated at
different resolutions. When I calculate things correctly, I get the
numbers I wanted.

Hi there,

I'm very interested in how to do this as well. I have a "map" image
and I want the users to click on the image and depending on the X,Y
location they clicked on I want to have a popup that access the DB
with the X.Y location and return the info. (the db has X,Y locations
stored and will compare the ones passed to the ones stored.

At the moment the only method I have thought of is by using a form.
function CityInfoWindow( ) {
NewWindow ('', 'CityInfo', 600, 400, 'yes', 'yes', -1, -1,
'');

<form name="frmCity" method="post" action="CityInf o.asp"
target="CityInf o">
<input type="image" src="CityMap.gi f" name="coords"
onClick="CityIn foWindow();">
</form>

I need the top left of the Image to be starting at 0,0 and for the
Javascript code to work in both IE 5.5+ and NS 7 at least.
Thanks for any help

Al.

Jul 23 '05 #5
On Sun, 22 Aug 2004 12:00:39 +0100, Harag
<ha************ **********@soft home.net> wrote:
Hi there,

I'm very interested in how to do this as well. I have a "map" image
and I want the users to click on the image and depending on the X,Y
location they clicked on I want to have a popup that access the DB
with the X.Y location and return the info. (the db has X,Y locations
stored and will compare the ones passed to the ones stored.

At the moment the only method I have thought of is by using a form.
function CityInfoWindow( ) {
NewWindow ('', 'CityInfo', 600, 400, 'yes', 'yes', -1, -1,
'');

<form name="frmCity" method="post" action="CityInf o.asp"
target="CityIn fo">
<input type="image" src="CityMap.gi f" name="coords"
onClick="CityI nfoWindow();">
</form>

I need the top left of the Image to be starting at 0,0 and for the
Javascript code to work in both IE 5.5+ and NS 7 at least.
Thanks for any help

Al.


Here's the code I ended up using to generate the x,y coordinates:

x=event.clientX + window.document .body.scrollLef t -
document.images[0].offsetLeft - 2;

y=event.clientY + window.document .body.scrollTop -
document.images[0].offsetTop- 2;

I'm writing strictly for the IE browser. I know you'll have to use
different code to capture the "event.clie ntX" and "event.clie ntY"
values in NS.

Good luck.

Jul 23 '05 #6
On Sun, 22 Aug 2004 12:00:39 +0100, Harag
<ha************ **********@soft home.net> wrote:

Thanks for any help

Al.


I've been working on this some more and have discovered that the
".offsetTop " property seems to always be "0" even though the image is
not at the top of the page. Apparently, the offset is measured from
the top of the "parent" object. In my case, I have the image in a
<DIV> tag so, I had to get that value. I don't know if it's the best
way but instead of "document.image s[0].offsetTop", I used
"document.image s[0].offsetParent.o ffsetTop"

This seems to yield a constant value - even at different screen
resolutions, it's always the same number.

HTH

Jul 23 '05 #7
Martin wrote on 22 aug 2004 in comp.lang.javas cript:
I've been working on this some more and have discovered that the
".offsetTop " property seems to always be "0" even though the image is
not at the top of the page. Apparently, the offset is measured from
the top of the "parent" object. In my case, I have the image in a
<DIV> tag so, I had to get that value. I don't know if it's the best
way but instead of "document.image s[0].offsetTop", I used
"document.image s[0].offsetParent.o ffsetTop"

This seems to yield a constant value - even at different screen
resolutions, it's always the same number.


offsetTop belongs to a style="position :absolute;" object

Do not use offsetTop with a object [like <div>]
that is not absolute positioned in it's container.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #8
Martin wrote:
<snip>
Here's the code I ended up using to generate the x,y coordinates:

x=event.clientX + window.document .body.scrollLef t -
document.images[0].offsetLeft - 2;

y=event.clientY + window.document .body.scrollTop -
document.images[0].offsetTop- 2;

I'm writing strictly for the IE browser. I know you'll have to use
different code to capture the "event.clie ntX" and "event.clie ntY"
values in NS.


IE browser mouse event objects have - offsetX/Y - properties that may be
a more direct way of achieving your goal (they are not well supported on
other browsers).

However, An element's total offset into a page is more complex than
just - document.images[0].offsetTop - because that represents the offset
to the element's - offsetParent -. When the element is not a direct
child of the BODY its - offsetTop/Left - may not be its page offset (CSS
absolute positioning also influences offset values).

Position information is available (where supported, as not all browsers
provide this info) by summing the - offsetTop/Left - values for each
element with all of its offset parent elements - offsetTop/Left - values
and then its offset parent's, until one of those elements has its -
offsetParent - property set to - null -. At least that is in the
simplest case; element's with borders and CSS overflow set so that they
scroll, add additional complexity to the calculations).

The constant value that you are using - 2 - is compensating for the -
clientTop/Left - property of the document.body element (on IE <= 5.5 and
IE 6 in "BackCompat " mode) and represents a default 2px inset border on
the root element. In principle that number is only the default and it is
possible for users to modify the border width on the root element (or
even a page designer through a CSS assignment). It would probably be
better to actually read the - document.body.c lientTop/Left - property to
acquire that number as then it will always represent the user's real
configuration.

On IE 6 it is possible to put the browser into "standards"
('CSS1Compat') mode, and if that happens the - scrollTop/Left - values
and the - clientTop/Left - values that apply to the root element are not
available from - document.body - but should instead be read from -
document.docume ntElement -. If there is a chance that the script will be
used in more than one context, or that the HTML design may at some point
change to be formally valid, it would be a good idea to be deciding
which of - document.body - or - document.docume ntElement - should be
read by checking the string value available from - docuemnt.compat Mode -
(which doesn't exist on IE <= 5.5). Archive searching for
"document.compa tMode" will turn up many examples and approaches.

Richard.
Jul 23 '05 #9
On Sun, 22 Aug 2004 19:53:07 +0100, "Richard Cornford"
<Ri*****@litote s.demon.co.uk> wrote:

snip...

Richard - Thanks for the explanation. I've learned a lot.

One thing I've learned, though, is that this is becoming more
complicated than it's worth (for my particular application).

As I mentioned at the top of this thread (I think), the "ismap"
function of an image gives me exactly the x/y coordinates that I'm
looking for. Do you (or anyone else) know if there's any way to
capture those values inside a script? They show up in the status
window only if an associated "href" has been specified but I'm
wondering if they're being generated by just declaring "ismap".

Any thoughts?

Thanks again.
Jul 23 '05 #10

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

Similar topics

1
2460
by: Scott M | last post by:
Hi, I am writing a small game that is using a form 800 * 600. The form can be scrolled vertically up to a height of 1200 (basically the form can be scrolled down one screen vertically). The user controls a picturebox (my sprite) with the cursor keys When the sprite hits the y value of 600 the screen scrolls down to display the bottom part of the screen (by focusing on a hidden
1
5359
by: Dave Harris | last post by:
I have written a reasonably clean way to perform coordinate transformations on a polygon, but Tkinter Canvas is not being particularly cooperative. The following program has been distilled down to a minimum and generates a traceback (see below) when it runs. It appears that the create_polygon() method is more versatile than the coords() method. Could someone can suggest a way to have the list comprehension not generate tuples, that...
1
2925
by: Vangelis Natsios | last post by:
I want to create a page with a scrolling image that will cause different messages to appear on another part of the page (say, another <div>) as the image will scroll. Imagine something like this: Image DIV Text DIV (Visible Area) +-----------+ Image +---------+ +-----------|------------------------+ | | | o | ...
2
10982
by: Stimp | last post by:
I remember doing something like this before, but it's been a while since I've touched javascript... I have a standard <img> and when a user clicks the image I want to output the IMAGE x y coordinates of the mouse click (i.e. not the page x y coords). I know that appending 'ismap' to the image tag will give me the image coordinates, but I can't use that since the img already has a 'usemap' attribute.
1
1376
by: Antonio Orozco | last post by:
Ok, here is the deal. I want to do this.... i have a group of cubes, i want to draw them, and then rotate, etc,etc. i've already tried DirectX 9 but now i want to draw the images direct to a picturebox... i know about some formulas, but i can't find them.... does anybody know how to do this???
3
2092
by: tommydog | last post by:
i am trying to generate an image map from the mouse coords of a click. i can pass the X Y through ok as $_POST $_POST how should the string be put into the AREA tag ? i am keeping the diameter as 10 this is what i am trying: echo "SHAPE=CIRCLE COORDS="'.$_POST.',143,10">";
3
12567
by: Matthias Vodel | last post by:
Hi all, I want to change the beginning/end-coordinates of a canvas.line item. Something like: self.myCanvas.itemconfigure(item_id, coords=(x1_new, y1_new, x2_new, y2_new)) I don't want to delete and repaint a new line item. Is this possible?
0
1955
by: Head In A Pan | last post by:
Hello! I have a basic javascript mouse tracker which captures the X&Y coords of the window & displays them in two separate text fields. What I am desperate to do is to post these values to dynamic text fields in a flash file in real time. The swf is sitting on a different frame within the same frameset. Has anyone done something similar before or able to help me? I am only just learning the basics of js.
1
2733
by: jojoba | last post by:
Hi I am trying to determine coordinates of something in a webpage. All i have is a subset of html that i know exists in a given webpage. Now i want to find that subsetHtml in the page and determine the exact pixel coordinates for the elements that subsetHtml comprises. I'm pretty sure i know how to get the pixel coords once i have the elements. The hard part is going from plain HTML to actual elements. Any ideas thx,
3
2823
by: Rhishabh07 | last post by:
how to define coords in an image for an area shape i m using <img src="left.jpg" width="350" height="29" alt="Planets" usemap ="#planetmap" /> <map id ="planetmap" name="planetmap"> <area shape ="rect" coords ="0,0,199,29" href ="sun.htm" alt="Sun"> <area shape ="circle" coords ="200,0,350,29" href ="mercur.htm" alt="Mercury">
0
9592
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
9425
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
10231
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
10005
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,...
1
7416
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
6679
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();...
1
3972
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 we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.