473,548 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Capturing client-side image coordinates

I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007 Firebird/0.7)
to do some client-side image processing. I want to capture the sequence of
coordinates a user clicks on in xxx.jpg in the following html

<a href="#"><IMG SRC="xxx.jpg" ISMAP></a>

and save these to a file for later handling. The coordinates appear on
the bottom left of the window as I move the mouse, so I know they're
being passed around somehow, but I haven't figured out how to 'catch'
them. (My apologies if this is a frequent Q. but a web search has led
to an answer). Help much appreciated.

--Tony
Jul 23 '05 #1
15 7031
Tony Gahlinger wrote:
I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007 Firebird/0.7)
to do some client-side image processing. I want to capture the sequence of
coordinates a user clicks on in xxx.jpg in the following html

<a href="#"><IMG SRC="xxx.jpg" ISMAP></a>

and save these to a file for later handling. The coordinates appear on
the bottom left of the window as I move the mouse, so I know they're
being passed around somehow, but I haven't figured out how to 'catch'
them. (My apologies if this is a frequent Q. but a web search has led
to an answer). Help much appreciated.

^^no^^

Oops! (If it led to an answer it was a null one!).

Any suggestions on how to capture/store clicked coordinates? Thanks.

--Tony
Jul 23 '05 #2
Tony Gahlinger wrote:
Tony Gahlinger wrote:
I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007 Firebird/0.7)
to do some client-side image processing. I want to capture the
sequence of coordinates a user clicks on in xxx.jpg in the following html


This uses some mouse tracking code I got from a website, it is used here
as an example, I would recommend looking for a better mouse-tracking
approach, maybe someone here will post a method that doesn't rely upon
browser detection. This works in my IE6, Netscape 7.1, Firefox 0.8 but I
have no idea what other browsers will do, esp. Opera.

What I did here was: track the mouse position, when the image is clicked
send the current mouse coordinates to a function that subtracts the
image position on the page (left, top) to get the image (x, y) position
of the mouse, store those numbers in an array.

I have no idea how to save the array contents to a file, sorry.
<script type="text/javascript">
//TRACK MOUSE BEGIN
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?tr ue:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captur eEvents(Event.M OUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmous emove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.s crollLeft
tempY = event.clientY + document.body.s crollTop
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
// catch possible negative values in NS4
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
// show the position values in the form named Show
// in the text fields named MouseX and MouseY
//document.Show.M ouseX.value = tempX
//document.Show.M ouseY.value = tempY
return true
}
//TRACK MOUSE END

//array to store mouse coord's
var coords=new Array();

//store mouse coord's in array after normalizing to img top, left

function storepoint(x,y, target){
//alert(x+', '+y+'\nTop '+target.offset Top+' Left '+target.offset Left);
alert((x-target.offsetLe ft)+', '+(y-target.offsetTo p));
//alert(target.of fsetTop);
//alert(document. getElementById( 'img1').left);
coords[coords.length]=[x-target.offsetLe ft,y-target.offsetTo p];
}

function showarr(){
var s1='';
for (var i=0; i<coords.length ; i++)
s1+='\n'+coords[i][0]+', '+coords[i][1];
alert(s1);
}

<img name="img1" id="img1" src="iamges/logo.gif" width="543"
height="113" onmousedown="st orepoint(tempX, tempY, this)">
</p>
<p>
<input type="button" value="Show Contents of Array (click coordinates)"
onclick="showar r()">

Good Luck,
Mike

Jul 23 '05 #3
mscir wrote:
Tony Gahlinger wrote:
Tony Gahlinger wrote:
I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007
Firebird/0.7)
to do some client-side image processing. I want to capture the
sequence of coordinates a user clicks on in xxx.jpg in the following
html

This uses some mouse tracking code I got from a website, it is used here
as an example, I would recommend looking for a better mouse-tracking
approach, maybe someone here will post a method that doesn't rely upon
browser detection. This works in my IE6, Netscape 7.1, Firefox 0.8 but I
have no idea what other browsers will do, esp. Opera.

What I did here was: track the mouse position, when the image is clicked
send the current mouse coordinates to a function that subtracts the
image position on the page (left, top) to get the image (x, y) position
of the mouse, store those numbers in an array.
...
Good Luck,
Mike


Thanks Mike. That's the part I was looking for.

--Tony
Jul 23 '05 #4
DU
mscir wrote:
Tony Gahlinger wrote:
Tony Gahlinger wrote:
I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007
Firebird/0.7)
to do some client-side image processing. I want to capture the
sequence of coordinates a user clicks on in xxx.jpg in the following
html

This uses some mouse tracking code I got from a website, it is used here
as an example, I would recommend looking for a better mouse-tracking
approach, maybe someone here will post a method that doesn't rely upon
browser detection. This works in my IE6, Netscape 7.1, Firefox 0.8 but I
have no idea what other browsers will do, esp. Opera.

What I did here was: track the mouse position, when the image is clicked
send the current mouse coordinates to a function that subtracts the
image position on the page (left, top) to get the image (x, y) position
of the mouse, store those numbers in an array.

I have no idea how to save the array contents to a file, sorry.
<script type="text/javascript">
//TRACK MOUSE BEGIN
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?tr ue:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captur eEvents(Event.M OUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmous emove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.s crollLeft
tempY = event.clientY + document.body.s crollTop
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
// catch possible negative values in NS4
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
// show the position values in the form named Show
// in the text fields named MouseX and MouseY
//document.Show.M ouseX.value = tempX
//document.Show.M ouseY.value = tempY
return true
}
//TRACK MOUSE END

//array to store mouse coord's
var coords=new Array();

//store mouse coord's in array after normalizing to img top, left

function storepoint(x,y, target){
//alert(x+', '+y+'\nTop '+target.offset Top+' Left '+target.offset Left);
alert((x-target.offsetLe ft)+', '+(y-target.offsetTo p));
//alert(target.of fsetTop);
//alert(document. getElementById( 'img1').left);
coords[coords.length]=[x-target.offsetLe ft,y-target.offsetTo p];
}

function showarr(){
var s1='';
for (var i=0; i<coords.length ; i++)
s1+='\n'+coords[i][0]+', '+coords[i][1];
alert(s1);
}

<img name="img1" id="img1" src="iamges/logo.gif" width="543"
height="113" onmousedown="st orepoint(tempX, tempY, this)">
</p>
<p>
<input type="button" value="Show Contents of Array (click coordinates)"
onclick="showar r()">

Good Luck,
Mike


That's awful! With MSIE, all you need to get is the offsetX and offsetY
event properties. That's all: no need for complex equations.
With Opera 7.x, you need to substract the border width from
event.offsetX/Y because there is a bug related to this (bug 123306).

With Mozilla, you need to cumulate the offsetLeft of elements in the
containment hierarchy of the image and then substract from the
evt.pageX/Y because there is no other way to do this in Mozilla.

DU
Jul 23 '05 #5
DU
Tony Gahlinger wrote:
I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007 Firebird/0.7)
to do some client-side image processing. I want to capture the sequence of
coordinates a user clicks on in xxx.jpg in the following html

<a href="#"><IMG SRC="xxx.jpg" ISMAP></a>

and save these to a file for later handling. The coordinates appear on
the bottom left of the window as I move the mouse, so I know they're
being passed around somehow, but I haven't figured out how to 'catch'
them. (My apologies if this is a frequent Q. but a web search has led
to an answer). Help much appreciated.

--Tony

You first need to set an event listener for the image, like this:

function init()
{
if(document.add EventListener)
{
document.getEle mentById("idIma geToMonitor").a ddEventListener ("mousemove" ,
TrackCoordinate sInImage, false);
}
else if(window.event && document.getEle mentById)
{
document.getEle mentById("idIma geToMonitor").o nmousemove =
TrackCoordinate sInImage;
};
}

function TrackCoordinate sInImage(evt)
{
var Coordinate_X_In Image, Coordinate_Y_In Image;
Coordinate_X_In Image = Coordinate_Y_In Image = 0;
if(window.event && !window.opera && typeof event.offsetX == "number")
/* MSIE 5+ */
{
var Coordinate_X_In Image = event.offsetX;
var Coordinate_Y_In Image = event.offsetY;
}
else if(document.add EventListener && evt && typeof evt.pageX == "number")
/* Mozilla-based browsers */
{
var Element = evt.target;
var CalculatedTotal OffsetLeft, CalculatedTotal OffsetTop;
CalculatedTotal OffsetLeft = CalculatedTotal OffsetTop = 0;
while (Element.offset Parent)
{
CalculatedTotal OffsetLeft += Element.offsetL eft ;
CalculatedTotal OffsetTop += Element.offsetT op ;
Element = Element.offsetP arent ;
};
Coordinate_X_In Image = evt.pageX - CalculatedTotal OffsetLeft ;
Coordinate_Y_In Image = evt.pageY - CalculatedTotal OffsetTop ;
};
}

In your html:

<body onload="init(); " ...>

I have pages which uses+explains this code, also for Opera 6.x and Opera
7.x.

DU
Jul 23 '05 #6
DU wrote:
<snip>

I tried your code, it looks a lot cleaner than the approach I posted,
and it works great in my (Win98 SE) IE6, but not in my Netscape 7.1 or
Firefox 0.8. Here's what I did:

function init(){
if(document.add EventListener) {
document.getEle mentById("idIma geToMonitor").a ddEventListener ("mousemove" ,
TrackCoordinate sInImage, false);
} else if(window.event && document.getEle mentById) {
document.getEle mentById("idIma geToMonitor").o nmousemove =
TrackCoordinate sInImage;
}
}

function TrackCoordinate sInImage(evt){
var Coordinate_X_In Image;
var Coordinate_Y_In Image;
Coordinate_X_In Image = Coordinate_Y_In Image = 0;
if(window.event && !window.opera && typeof event.offsetX == "number") {
// IE 5+
var Coordinate_X_In Image = event.offsetX;
var Coordinate_Y_In Image = event.offsetY;
} else if(document.add EventListener && evt && typeof evt.pageX ==
"number"){
// Mozilla-based browsers
var Element = evt.target;
var CalculatedTotal OffsetLeft, CalculatedTotal OffsetTop;
CalculatedTotal OffsetLeft = CalculatedTotal OffsetTop = 0;
while (Element.offset Parent) {
CalculatedTotal OffsetLeft += Element.offsetL eft ;
CalculatedTotal OffsetTop += Element.offsetT op ;
Element = Element.offsetP arent ;
}
Coordinate_X_In Image = evt.pageX - CalculatedTotal OffsetLeft ;
Coordinate_Y_In Image = evt.pageY - CalculatedTotal OffsetTop ;
}
document.getEle mentById('div1' ).innerText = "X:
"+Coordinate_X_ InImage+" Y: "+Coordinate_Y_ InImage;
}
I have pages which uses+explains this code, also for Opera 6.x and Opera 7.x.
DU


Would you post the URL with code explanations so I can read up on this?

Thanks,
Mike

Jul 23 '05 #7
DU
mscir wrote:
DU wrote:
<snip>

I tried your code, it looks a lot cleaner than the approach I posted,
and it works great in my (Win98 SE) IE6, but not in my Netscape 7.1 or
Firefox 0.8.
innerText is not a W3C DOM 2 attribute nor a DOM 2 CharacterData
attribute. nodeValue though is and it is supported by MSIE 6!

Here's what I did:
function init(){
if(document.add EventListener) {
document.getEle mentById("idIma geToMonitor").a ddEventListener ("mousemove" ,
TrackCoordinate sInImage, false);
} else if(window.event && document.getEle mentById) {
document.getEle mentById("idIma geToMonitor").o nmousemove =
TrackCoordinate sInImage;
}
}

function TrackCoordinate sInImage(evt){
var Coordinate_X_In Image;
var Coordinate_Y_In Image;
Coordinate_X_In Image = Coordinate_Y_In Image = 0;
if(window.event && !window.opera && typeof event.offsetX == "number") {
// IE 5+
var Coordinate_X_In Image = event.offsetX;
var Coordinate_Y_In Image = event.offsetY;
} else if(document.add EventListener && evt && typeof evt.pageX ==
"number"){
// Mozilla-based browsers
var Element = evt.target;
var CalculatedTotal OffsetLeft, CalculatedTotal OffsetTop;
CalculatedTotal OffsetLeft = CalculatedTotal OffsetTop = 0;
while (Element.offset Parent) {
CalculatedTotal OffsetLeft += Element.offsetL eft ;
CalculatedTotal OffsetTop += Element.offsetT op ;
Element = Element.offsetP arent ;
}
Coordinate_X_In Image = evt.pageX - CalculatedTotal OffsetLeft ;
Coordinate_Y_In Image = evt.pageY - CalculatedTotal OffsetTop ;
}
document.getEle mentById('div1' ).innerText = "X:
"+Coordinate_X_ InImage+" Y: "+Coordinate_Y_ InImage;

Change that above line to this:

if(document.get ElementById('di v1').childNodes[0] &&
document.getEle mentById('div1' ).childNodes[0].nodeType == 3)
{
document.getEle mentById('div1' ).childNodes[0].nodeValue = "X:
" + Coordinate_X_In Image + " Y: " + Coordinate_Y_In Image;
}

and make sure that div1 is without blank spaces (or is truly the first
text node), like this:
<div id="div1">&nbsp ;</div>

and this should work without a problem on all W3C DOM 2 CharacterData
conforming agent (that includes MSIE 6).

Demos:
Performance comparison between innerHTML attribute and DOM's nodeValue
when modifying the text data of a node of type TEXT_NODE
http://www10.brinkster.com/doctorunc...NodeValue.html

Interactive DOM level 2 CharacterData Interface attributes and methods
tests:
http://www10.brinkster.com/doctorunc...acterData.html
}
I have pages which uses+explains this code, also for Opera 6.x and
Opera 7.x.
DU

Would you post the URL with code explanations so I can read up on this?

Thanks,
Mike


Here's a few:

(use MSIE 6 for this link)
http://www10.brinkster.com/doctorunc...dowsMSIE6.html
(use a Mozilla-based browser for this link)
http://www10.brinkster.com/doctorunc...nerWidthHeight
In the code of that page, I commented the part like this in function
MovesInNS6(evt)

/*
var elem = evt.target ;
var CalculatedTotal OffsetLeft = CalculatedTotal OffsetTop = 0;
while (elem.offsetPar ent)
{
CalculatedTotal OffsetLeft += elem.offsetLeft ;
CalculatedTotal OffsetTop += elem.offsetTop;
elem = elem.offsetPare nt;
}
*/

and I explained it around the area of the anchor #windowInnerWid thHeight

(use Opera 7 for this link)
http://www10.brinkster.com/doctorunc...WindowsO7.html

(use Opera 6 for this link)
http://www10.brinkster.com/doctorunc...WindowsO6.html

(use Opera 7 for this link)
http://www10.brinkster.com/doctorunc...pera7Bugs.html
and go+click item #11- event.offsetX and event.offsetY coordinate
values... for the demo:
http://www10.brinkster.com/doctorunc...gOffsetXY.html

DU
Jul 23 '05 #8
DU wrote:
mscir wrote:
DU wrote:
<snip>
I tried your code, it looks a lot cleaner than the approach I posted,
and it works great in my (Win98 SE) IE6, but not in my Netscape 7.1 or
Firefox 0.8.
<snip>
innerText is not a W3C DOM 2 attribute nor a DOM 2 CharacterData
attribute. nodeValue though is and it is supported by MSIE 6!


Apologies, your code works great, thanks for pointing out my mistake.
Thanks for the links too,
Mike
Jul 23 '05 #9
mscir wrote:
DU wrote:
<snip>

I tried your code, it looks a lot cleaner than the approach I posted,
and it works great in my (Win98 SE) IE6, but not in my Netscape 7.1 or
Firefox 0.8. Here's what I did:

<snip>

Would you post the URL with code explanation so I can read up on this?

Thanks,
Mike
Hmm .. you guys are leaving me in the dust. Do I replace mscir's first code set
entirely with DU's, or do I still need pieces of it? In particular, what would
come after DU's '...' below:
In your html:

<body onload="init(); " ...>


Do I still need mscir's storepoint or showarr functions?

I'd also be much interested in DU's code/explanations. Appreciate both your
efforts. Thanks.

--Tony
Jul 23 '05 #10

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

Similar topics

2
1955
by: jerrygarciuh | last post by:
Hello, I have a client who has decided to output the OO PHP/mySQL site I have made for them onto a cd. I realize that $html = include('somefile.php'); gets 1 for success as its return value. In what manner can I access my files so what would be output to the browser from 'someFile.php?id=1213'
0
1115
by: Andy | last post by:
Hi All, Im creating a connectionless udp server and client using the Async method of the Socket class, ie. this.m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); Is there any way of capturing the IPAddress/Port of the sending client? I have tried using the SendTo and Socket.BeginReceiveFrom although...
7
20362
by: jerrygarciuh | last post by:
Hello, I have been playing with various Googled solutions for capturing the <Enter> key to suppress form submission. My first question is whether anyone has a script that works in all common browsers? The script bellow is IE only. It fails FF 1.0 and NN 7. Also, if I can trap the keypress I would like to use it to tab to the next...
33
5577
by: Joerg Schuster | last post by:
Hello, Python regular expressions must not have more than 100 capturing groups. The source code responsible for this reads as follows: # XXX: <fl> get rid of this limitation! if p.pattern.groups > 100: raise AssertionError( "sorry, but this version only supports 100 named groups"
1
1294
by: Brad | last post by:
Hello all. I'm trying to convert an application with a SQL Server 2000 back end and an Access front-end. The back end is fine. I'm just trying to give it a web front-end using ASP.NET. The problem is that since Access runs on the client machine, it gathers NT authentication information at the client and uses that to access the database. ...
6
2252
by: Ed Leafe | last post by:
I've been approached by a local business that has been advised that they need to start capturing and archiving their instant messaging in order to comply with Sarbanes-Oxley. The company is largely PC, but has a significant number of Macs running OS X, too. Googling around quickly turns up IM Grabber for the PC, which would seem to be just...
0
1474
by: hepsubah | last post by:
I'm trying to capture a client cert in my ASP.NET application, and use that cert as the client cert for a call to secure web service. I've used the following code, but am getting a 403 error on the invocation of the service. All the service is supposed to do is return the subject of the passed cert (I'll do more with it later) ...
7
2955
by: David Lozzi | last post by:
Howdy, I'm trying to capture the session end event. I put a spot of code in the Session_End event in the Global.asax.vb file. The function simply writes to a database table logging the event. I have the same function in the Session_Begin and the Application events. I am capturing the Session beginning and the App begin and end but no...
1
1436
by: sachinsjoshi | last post by:
Dear all, I have struck in one of the different type of requirement in SQL Server 2005. I need an equivalent functionality of capturing date and time based on client's timezime, as it is possible in Oracle by using LOCALTIMESTAMP() which will capture the session's date and time based on the time zone. Can anyone get me the solution?
0
7951
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
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...
0
7803
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6036
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...
1
5362
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...
0
3495
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1926
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
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
751
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...

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.