用JS的方式获取就要用getBoundingClientRect方法,like this:
window.frames['mainframe'].document.getElementById('Img').getBoundingClientRect().left;
但是JS时灵时不灵,下面就是不用JS的方法:
public Point GetOffset(HtmlElement el) { //get element pos Point pos = new Point(el.OffsetRectangle.Left, el.OffsetRectangle.Top); //get the parents pos HtmlElement tempEl = el.OffsetParent; while (tempEl != null) { pos.X += tempEl.OffsetRectangle.Left; pos.Y += tempEl.OffsetRectangle.Top; tempEl = tempEl.OffsetParent; } return pos; } var point = GetOffset(element); var x = point.X; var y = point.Y;