Jump to content

Absolute pixel coordinates of a HTML object in an IE window (including title bar/menu/etc.)


Recommended Posts

Imagine you have an IE window :

- At the top of it you have the title bar, the menu, the toolbars, etc.

- Just below the aforementionned, you have the HTML document

It has been shown that it is possible to calculate the absolute pixel position of an HTML object from the top of the HTML document (see)

...But...

Is it possible to calculate the absolute pixel position of an HTML object from the top of the IE window?

Another way to ask the question is: "Is it possible to calculate the pixel height of all the IE crap that comes above the HTML page?"

so far, I have gathered this :

1. Method #1

You can use $oIE.document.parentWindow.

This is of type "window" (see members here)

Then, the closest I can get is to calculate outerHeight-InnerHeight.

Yet, one still doesn't know what part of the result represents what comes above the HTML, and what comes below (e.g. the status bar)

I haven't found out a way to work around this.

EDIT: Actually, does this "parentWindow" point to the whole IE window, or only to the client area where the HTML page gets rendered?

I've done some tests, and $oIE.document.parentwindow.parent.parent.parent.parent... always seems to point to the same thing, but I can't quite tell what.

2. Method #2

It has been suggested to use "controlGetPos", but I must admit I don't understand at all how to turn an HTML object into a controlthat can be fed to that function...

Edited by MonsieurOUXX
Link to comment
Share on other sites

Hi again,

EDIT: Actually, does this "parentWindow" point to the whole IE window, or only to the client area where the HTML page gets rendered?

You can test this by checking the values you get from the object after you positioned the IE window on your screen to lets say 0,0 ?

Edit: removed question, wrote something about your second question

Since you already know how to get the offset from within the HTML document you can combine that with the browsers "inner window" position.

The browser window you see with the title bar and such is the "window". The view that holds the HTML page inside of that is a control.

So if you know the class of the control (Internet Explorer_Server), you can use ControlGetPos to get the position on screen,

for the window title use the IE object's document title.

#include <IE.au3>
 
$oIE = _IECreate("http://autoitscript.com", 1) ; create IE object
 
$aCtrlPos = ControlGetPos($oIE.document.title, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
 
ConsoleWrite("CtrlPos: " & $aCtrlPos[0] & "x" & $aCtrlPos[1] & @CRLF)

Edit 2: Added the FF version

Here is an example of how to obtain the position of an HTML element relative to the screen in FireFox.

There may well be a better way to do this but I never used the FireFox UDF.

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#Include <FF.au3>
 
 
; Get the position of an HTML element relative to the screen (just a testcase)
If _FFConnect(Default, Default, 3000) Then ; trying to connect to a running FireFox with MozRepl on
    ; open a page
    _FFOpenURL("http://google.com/")
    Sleep(1000)
 
    $hWin = _FFWindowGetHandle()
 
    $aWinPos = WinGetPos($hWin)
    ConsoleWrite("-> FF WinPos: " & $aWinPos[0] & "x" & $aWinPos[1] & @CRLF)
 
    ; I think this works only up to ff 3 because of MozillaContentWindowClass, after ff3 its content all the way
;~   $aCtrlPos = ControlGetPos($hWin, "", "[CLASS:MozillaContentWindowClass]")
;~   ConsoleWrite("-> ViewPos: " & $aCtrlPos[0] & "x" & $aCtrlPos[1] & @CRLF)
 
    $offsetTop = $aWinPos[1] ; we start with the window position Y
    $offsetTop += _FFCmd("getBrowser().selectedBrowser.getBoundingClientRect().top") ; add the menubar/toolbar etc. height
    $offsetTop += _WinAPI_GetSystemMetrics($SM_CYCAPTION) + 3 ; get the system titlebar height, add 3 for the border
    ConsoleWrite("-> FF content window offset top: " & $offsetTop & @CRLF) ; now we have the top offset of the content view
 
    $offsetTop += _FFCmd("content.wrappedJSObject.document.getElementById('hplogo').offsetTop") ; this routine should be updated to take parentNodes etc. into account
    ConsoleWrite("-> HTML element offset top: " & $offsetTop & @CRLF) ; now we have the top offset of the content view
 
    ; disconnect from FireFox
    _FFDisConnect()
Else
    MsgBox(64, "", "Can't connect to FireFox!")
EndIf

FireFox UDF: (FF.au3)

Edited by Robjong
Link to comment
Share on other sites

Did you look at _IEPropertyGet() ?

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

By your reponse, I presume you have not looked at the documentation in the hepfile for _IEPropertyGet()

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...