No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
http:Q_21348166.html--> Accept dakyd's comment as the answer.
Any objections should be posted here in the next 4 days. After that time, the question will be closed.
~Aqua
EE Cleanup Volunteer
If the Author does not know how to close the question, the options are here:
http://www.experts-exchang
Main Topics
Browse All Topics





by: dakydPosted on 2005-03-14 at 13:31:18ID: 13539184
Is this more like what you want? It compensates for scrolling, in both Mozilla & IE6. Don't have access to Safari, so can't tell you what it does there. Still, hope that helps.
4/strict.d td">
c").value = x; c").value = y;
crollTop) crollLeft; crollTop;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html
<html>
<head>
<script type="text/javascript">
function getCoords(evt, theObj)
{
var e = window.event? window.event: evt;
// get coords first
var x = e.pageX? e.pageX: e.clientX;
var y = e.pageY? e.pageY: e.clientY;
// subtract img top & left & compensate for scrolling
x -= getX(theObj);
y -= getY(theObj);
if (!e.pageY)
{
var scrollOffsets = new Array();
scrollOffsets = getScrollOffset();
x += scrollOffsets[0];
y += scrollOffsets[1];
}
/* these next two lines are just for output
you can remove them if you don't need them */
document.getElementById("x
document.getElementById("y
}
function getX(obj)
{
var x = 0;
temp = obj;
while (temp.offsetParent)
{
x += temp.offsetLeft;
temp = temp.offsetParent;
}
return x;
}
function getY(obj)
{
var y = 0;
temp = obj;
while (temp.offsetParent)
{
y += temp.offsetTop;
temp = temp.offsetParent;
}
return y;
}
function getScrollOffset()
{
var x,y;
if (self.pageYOffset) // all except Explorer
{
x = self.pageXOffset;
y = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.s
// Explorer 6 Strict
{
x = document.documentElement.s
y = document.documentElement.s
}
else if (document.body) // all other Explorers
{
x = document.body.scrollLeft;
y = document.body.scrollTop;
}
var answer = new Array(x, y);
return answer;
}
</script>
<style type="text/css">
img {
margin-top: 50px;
margin-left: 50px;
display: block;
}
div {
height: 800px;
}
</style>
</head>
<body>
<img src="test.jpeg" onclick="getCoords(event, this);" />
<label for="xc">X Coordinate:</label>
<input type="text" id="xc" name="xc" />
<label for="yc">Y Coordinate:</label>
<input type="text" id="yc" name="yc" />
<div>Not useful at all, just here to lengthen the page</div>
</body>
</html>