View Full Version : windows coordinates mouseover

06-09-2007, 11:57 AM
I have a page which contain small images
I want to get the windows coordinates for every small image
IS this Possible in php/javascript

Please send the example code if any.

06-09-2007, 04:42 PM
PHP is not capable of handling mouseover events - it is preprocessed.
Javascript is capable of recording position x and y for any html element.
Examples... not sure if I can help you with that as my js is quite rusty, but I'll give it a shot:

<script type="text/javascript">
var images = document.getElementsByTagName("image");
var imageLocs = new Array();
for (var i = 0; i < images.length(); i++)
imageLocs[i] = new Array(images[i].offsetX, images[i].offsetY);

Ok... didn't test that out and honestly I don't think it will work. Lol, not even certain if the javascript syntax is correct on that one :P
Unfortunatly, if I remember correctly, offset* retrieves the offset relative to a specified element. This element changes from browser to browser.
Anyway, post it up in the js forum, surely someone can help you there!

Mr J
06-10-2007, 12:17 AM
Give this a try

<script type="text/javascript">

onload=function test(){
var images = document.getElementsByTagName("img");
var imageLocs = new Array();

for(var i = 0; i < images.length; i++){
imageLocs[i] = new Array(images[i].offsetLeft, images[i].offsetTop);


This is on the premise that the images are in the natural flow of the document.
If they are in a table or nested in positioned divs additional code will be required

06-12-2007, 03:07 PM
Try the FindPos scripts by Peter-Paul Koch at:


and its update (to work with Safari) by Alex Tingle at: