SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : Dynamic HTML :

Previous DiscussionNext Discussion
 How can I find location of an object in page?

When the user clicks a button, I'd like to be able to send the ID of its container object (e.g., a table) to (presumably) a Javascript routine to find out the top and left pixel coordinates of the object -- relative to the screen and/or browser window. Anyone know whether this can be done and how to go about it?

To trigger the same process, is it possible to capture the click event of the browser's scroll bars?

Started By scwilson on Oct 20, 2004 at 3:53:44 PM

13 Response(s) | Reply

View All Replies | Goto Page: 2 1
hedger on Oct 20, 2004 at 7:32:26 PM

Oh thanks God and dear ChrisRickard .

document.getBoxObjectFor()  is exactlly what I need.

Where did you learn that?

here is the general solution

function getPos(el) {
var x,w,y,h;
if (document.getBoxObjectFor) {
var bo = document.getBoxObjectFor(el);
x = bo.x;
w = bo.width;
y = bo.y;
h = bo.height;
}
else if (el.getBoundingClientRect) {
var rect = el.getBoundingClientRect();
x = rect.left;
w = rect.right - rect.left;
y = rect.top;
h = rect.bottom - rect.top;

el.x = x;
el.y=y;
el.w= w;
el.h = h;
alert("Left: " + x + "\rTop: " + y + "\rWidth: " + w + "\rHeight: " + h);
}


 


View All Replies | Goto Page: 2 1

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2000 InsideDHTML.com, LLC. All rights reserved.