Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

21 Mar 2017, 02:58

I created a script to get the element under the cursor in Internet Explorer (regardless of the zoom percentage). It could potentially be incorporated into an update of iWB2 Learner.

The script puts temporary borders around, and gets text from, the element under the cursor.

It seems to always work correctly, however, if anyone notices an error or omission, or script issue, please comment below, because I would want something potentially widely used like this to be perfect. If anyone has written something similar, also, please inform me.

It uses 4 lots of SplashImage to show the borders around the element.

Code: Select all

#IfWinActive, ahk_class IEFrame
q:: ;internet explorer - get element under cursor
;show borders around, and get text from, element under cursor
;regardless of zoom percentage of 'Internet Explorer_Server' control
;it could potentially be incorporated into iWB2 Learner
IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"

CoordMode, Mouse, Screen
MouseGetPos, vMouseX, vMouseY,, hCtl, 3
WinGetClass, vCtlClass, % "ahk_id " hCtl
if !(vCtlClass == "Internet Explorer_Server")
	return
if !(oDoc := ComObject(9,ComObjQuery(Acc_ObjectFromWindow(hCtl),IID_IHTMLWindow2,IID_IHTMLWindow2),1).document)
	return
oWin := ComObject(9,ComObjQuery(oDoc,IID_IHTMLWindow2,IID_IHTMLWindow2),1)
oWB := ComObject(9,ComObjQuery(oWin,IID_IWebBrowserApp,IID_IWebBrowserApp),1)

vLogicalXDPI := oWB.document.parentWindow.screen.logicalXDPI
vDeviceXDPI := oWB.document.parentWindow.screen.deviceXDPI
vZoomRatio := vDeviceXDPI / vLogicalXDPI

;vWinX := oWin.screenLeft, vWinY := oWin.screenTop
;WinGetPos, vWinX2, vWinY2, vWinW2, vWinH2, ahk_class IEFrame
WinGetPos, vCtlX, vCtlY, vCtlW, vCtlH, ahk_id %hCtl%
vMouseX2 := (vMouseX-vCtlX)*(1/vZoomRatio)
vMouseY2 := (vMouseY-vCtlY)*(1/vZoomRatio)

oElt := oWin.document.elementFromPoint(vMouseX2, vMouseY2)
oRect := oElt.getBoundingClientRect()
vEltX := vCtlX + (oRect.left * vZoomRatio)
vEltY := vCtlY + (oRect.top * vZoomRatio)
vEltW := (oRect.right - oRect.left) * vZoomRatio
vEltH := (oRect.bottom - oRect.top) * vZoomRatio

JEE_Borders(vEltX, vEltY, vEltW, vEltH, 1000, "FFFF00")
MsgBox % oElt.tagName "`r`n" oElt.innerText
oDoc := oWin := oWB := oElt := oRect := ""
return
#IfWinActive

;==================================================

JEE_Borders(vPosX, vPosY, vPosW=0, vPosH=0, vTime=1000, vCol="FFFF00")
{
CoordMode, Pixel, Screen
vBorderH := 5 ;height of border
vBorderW := 5 ;width of border
SplashImage, 1:, % "B W" vPosW+(2*vBorderW) "H" vBorderH "X" vPosX-vBorderW "Y" vPosY-vBorderH "Cw" vCol,,, SP1 ;top
SplashImage, 2:, % "B W" vPosW+(2*vBorderW) "H" vBorderH "X" vPosX-vBorderW "Y" vPosY+vPosH "Cw" vCol,,, SP2 ;bottom
SplashImage, 3:, % "B W" vBorderW "H" vPosH+(2*vBorderH) "X" vPosX-vBorderW "Y" vPosY-vBorderH "Cw" vCol,,, SP3 ;left
SplashImage, 4:, % "B W" vBorderW "H" vPosH+(2*vBorderH) "X" vPosX+vPosW "Y" vPosY-vBorderH "Cw" vCol,,, SP4 ;right
Sleep % vTime
SplashImage, 1: Off
SplashImage, 2: Off
SplashImage, 3: Off
SplashImage, 4: Off
Return
}

;==================================================
Last edited by jeeswg on 10 Nov 2017, 16:43, edited 3 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

23 Mar 2017, 12:56

Very nice! I saw this on StackOverflow, but I tried

Code: Select all

window.devicePixelRatio
without success!
P.s.: Works a bit slow, I think and it seems to be a problem if multiple IE windows are opened, not sure, made just a quick test, anyway thanks!
Edit: I couldn't confirm reported problems, since relevant IE window was corrupt. I realized that after iWB2_Learner and ACC_Viewer stopped working too. Strangely the window itself still works!
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

18 Aug 2017, 09:43

https://autohotkey.com/boards/viewtopic ... 263#p27263 I dunno bout getting the zoom level tho. see if this simple code helps you get started
except for the zoom level what your trying to do has been done win the iwebbrowser learner
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

18 Aug 2017, 12:05

@tank: Yes, iWB2 Learner has the limitation that it can only work properly if you set the zoom in Internet Explorer to 100%, so the aim of this script was to find some code that could be used to improve iWB2 Learner.

It has not been easy to improve iWB2 Learner, I plan to try and rewrite it from scratch, and at that point, understanding the script better, either create a rewritten version (more likely), or amend the existing version (possible).

A script to get the zoom percentage from Internet Explorer:
Internet Explorer get/set zoom/text size - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 74#p165674
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

18 Aug 2017, 12:18

jeeswg wrote: I plan to try and rewrite it from scratch
If you do it for v2, it needn't be improved to be valuable. :mrgreen:

Cheers.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

18 Aug 2017, 12:27

I tried to amend the script to work with an old version of AHK v2 that supported the Gui command, but the problems relating to understanding how the script works, and new AHK v2 errors have made that very difficult. Also I'll have to learn the new GUI functions/objects.

I'll be back though, with improved AHK v1/v2 versions of iWB2 Learner and AccViewer at some point:
Acc / AccViewer / iWB2 Learner / Anchor conversion attempts - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=30606

Well, I'll start off with rewrites (no functionality added), and then improved versions. So 2 original scripts * 2 AHK versions * 2 script versions = 8 scripts in total.
Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

25 Aug 2017, 22:58

Get the screen coordinates for a specific web element in Internet Explorer. See above for the JEE_Borders function, which puts a temporary coloured border around the specified screen coordinates.

Code: Select all

;e.g.
;WinGet, hWnd, ID, A
;oWB := WBGet("ahk_id " hWnd)
;oElt := oWB.document.activeElement
;JEE_IntExpEltGetPos(hWnd, oWB, oElt, vEltX, vEltY, vEltW, vEltH)
;JEE_Borders(vEltX, vEltY, vEltW, vEltH)
;MsgBox, % vEltX " " vEltY " " vEltW " " vEltH
;oWB := oElt := ""
;return

;JEE_IntExpElementGetPos
JEE_IntExpEltGetPos(hWnd, oWB, oElt, ByRef vEltX, ByRef vEltY, ByRef vEltW, ByRef vEltH)
{
	vLogicalXDPI := oWB.document.parentWindow.screen.logicalXDPI
	vDeviceXDPI := oWB.document.parentWindow.screen.deviceXDPI
	vZoomRatio := vDeviceXDPI / vLogicalXDPI

	ControlGet, hCtl, Hwnd,, Internet Explorer_Server1, % "ahk_id " hWnd
	WinGetPos, vCtlX, vCtlY, vCtlW, vCtlH, % "ahk_id " hCtl
	oRect := oElt.getBoundingClientRect()
	vEltX := vCtlX + (oRect.left * vZoomRatio)
	vEltY := vCtlY + (oRect.top * vZoomRatio)
	vEltW := (oRect.right - oRect.left) * vZoomRatio
	vEltH := (oRect.bottom - oRect.top) * vZoomRatio
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

01 Sep 2017, 02:28

A function to get the element under the cursor.

[WBGet function]
Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
https://autohotkey.com/board/topic/4705 ... -tutorial/

See above for JEE_IntExpEltGetPos and JEE_Borders functions.

Code: Select all

q::
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
JEE_IntExpGetEltUnderCursor(oWB, oElt)
;JEE_IntExpEltGetPos(hWnd, oWB, oElt, vEltX, vEltY, vEltW, vEltH)
;JEE_Borders(vEltX, vEltY, vEltW, vEltH)
vSrc := oElt.src
oWB := oElt := ""
MsgBox, % vSrc
return

;==================================================

JEE_IntExpGetEltUnderCursor(ByRef oWB, ByRef oElt)
{
	IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
	IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"

	CoordMode, Mouse, Screen
	MouseGetPos, vCurX, vCurY,, hCtl, 3
	WinGetClass, vCtlClass, % "ahk_id " hCtl
	If !(vCtlClass = "Internet Explorer_Server")
		return
	if !pdoc := ComObject(9,ComObjQuery(Acc_ObjectFromWindow(hCtl), IID_IHTMLWindow2, IID_IHTMLWindow2),1).document ; document property will fail if no valie com object
		return

	pwin := ComObject(9, ComObjQuery(pdoc, IID_IHTMLWindow2, IID_IHTMLWindow2), 1)
	oWB := ComObject(9, ComObjQuery(pwin, IID_IWebBrowserApp, IID_IWebBrowserApp), 1)

	vLogicalXDPI := oWB.document.parentWindow.screen.logicalXDPI
	vDeviceXDPI := oWB.document.parentWindow.screen.deviceXDPI
	vZoomRatio := vDeviceXDPI / vLogicalXDPI

	WinGetPos, vCtlX, vCtlY,,, % "ahk_id " hCtl
	vPosX := (vCurX-vCtlX)*(1/vZoomRatio)
	vPosY := (vCurY-vCtlY)*(1/vZoomRatio)
	oElt := pwin.document.elementFromPoint(vPosX, vPosY)
}
Last edited by jeeswg on 01 Sep 2017, 08:31, edited 3 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

01 Sep 2017, 08:19

Just a thought. When you post these maybe put links to the library items your using?
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

02 Sep 2017, 01:42

Get column under cursor.
- If the element under the cursor is the cell (TD), then the parent is the row (TR), and the grandparent is the table (TBODY).
- To know which column to grab: there may be a better way but the script loops through the innerText for each cell in the current row, until it finds a match (i.e. the cell under the cursor.)
- The script finds each row in the body, and grabs the nth cell in each row.

See above for: WBGet and JEE_IntExpGetEltUnderCursor functions.

Code: Select all

;example webpages for testing script:
;List of countries and dependencies by population - Wikipedia
;https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population
;Variables and Expressions
;https://autohotkey.com/docs/Variables.htm#BuiltIn

q:: ;internet explorer - get column under cursor
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
JEE_IntExpGetEltUnderCursor(oWB, oElt)
oElt2 := oElt.parentNode.parentNode
;JEE_IntExpEltGetPos(hWnd, oWB, oElt2, vEltX, vEltY, vEltW, vEltH)
;JEE_Borders(vEltX, vEltY, vEltW, vEltH)

vNum := ""
Loop, % oElt.parentNode.childNodes.length
	try if (oElt.innerText = oElt.parentNode.childNodes.item[A_Index-1].innerText)
		vNum := A_Index-1
if (vNum = "")
{
	oWB := oElt := oElt2 := oElt3 := ""
	return
}

vOutput := ""
VarSetCapacity(vOutput, 100000*2)
vEltTag := "TR"
Loop, % oElt2.getElementsByTagName(vEltTag).length
{
	oElt3 := oElt2.getElementsByTagName(vEltTag).item[A_Index-1]
	vOutput .= oElt3.childNodes.item[vNum].innerText "`r`n"
}
Clipboard := vOutput
MsgBox, % vOutput
oWB := oElt := oElt2 := oElt3 := ""
return
Get table under cursor.

Code: Select all

q:: ;internet explorer - get table under cursor
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
JEE_IntExpGetEltUnderCursor(oWB, oElt)
oElt2 := oElt.parentNode.parentNode
;JEE_IntExpEltGetPos(hWnd, oWB, oElt2, vEltX, vEltY, vEltW, vEltH)
;JEE_Borders(vEltX, vEltY, vEltW, vEltH)

vOutput := ""
VarSetCapacity(vOutput, 100000*2)
vEltTag := "TR"
Loop, % oElt2.getElementsByTagName(vEltTag).length
{
	oElt3 := oElt2.getElementsByTagName(vEltTag).item[A_Index-1]
	Loop, % oElt3.childNodes.length
		try vOutput .= oElt3.childNodes.item[A_Index-1].innerText "`t"
	vOutput := SubStr(vOutput, 1, -1) "`r`n"
}
Clipboard := vOutput
MsgBox, % vOutput
oWB := oElt := oElt2 := oElt3 := ""
return
Get row under cursor.

Code: Select all

q:: ;internet explorer - get row under cursor
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
JEE_IntExpGetEltUnderCursor(oWB, oElt)
;JEE_IntExpEltGetPos(hWnd, oWB, oElt2, vEltX, vEltY, vEltW, vEltH)
;JEE_Borders(vEltX, vEltY, vEltW, vEltH)

vOutput := ""
VarSetCapacity(vOutput, 100000*2)
Loop, % oElt.parentNode.childNodes.length
	try vOutput .= oElt.parentNode.childNodes.item[A_Index-1].innerText "`t"
vOutput := SubStr(vOutput, 1, -1)
Clipboard := vOutput
MsgBox, % vOutput
oWB := oElt := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
TheDewd
Posts: 1506
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 10:10

How can I use this on a website that uses iFrames. The website has 3 iFrames (Top, Left, Right). The website's contents are displayed inside the frames.

The script only works if I open the URL of the page inside the iFrame in a new tab/window.

I want to create a script that performs different actions based on the element under the mouse cursor.

For example, I would create a right-click menu, but the menu options would be different depending on the item I right-clicked on the website.

To get the data from inside the iFrame, I currently use something like this:

Code: Select all

For Window In ComObjCreate("Shell.Application").Windows {
    If (Window.LocationName = "Website Title") {
        Main := Window.Document.parentWindow.frames["body"].frames["main"].Document
        
        If (Main.Title = "Title of page inside iframe") {
            MsgBox, % Main.getElementById("TheElementID").outerHTML
        }
    }
}
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 13:46

This script gets frames but coordinates are not suited for zoom
https://autohotkey.com/boards/viewtopic ... 263#p27263
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
TheDewd
Posts: 1506
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 13:59

@tank: That's exactly what I needed! This should be fine for me, but if I needed to share with others who are using zoom are there any ways to make it work?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 14:31

@TheDewd:
- Does my script not work on websites that use frames? What exactly is the problem?
- Please provide me with the names of any websites (that don't require a login) that you know of, that use frames, so I can test my script. (I don't know from memory of any such websites.)
- Even if tank's solution works for you, I think this is worth investigating. Thanks.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
TheDewd
Posts: 1506
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 14:57

@jeeswg:

Tank's solution works, but if possible it would be great to not rely on having the zoom at 100%. I tried to combine your solution with tank's, but I've had no success. The coordinates are always offcenter when zoomed in.

The website is not public. It is for my job/work.

Your script only puts the borders around the top & bottom frame -- not the content inside the frames.

It's complicated because it's using iFrames within iFrames (Multi-Level). See below...

Here's the source code of the initial page (TOP & BODY):

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
	<head>
		<title>
			First Source
		</title>  
	</head>
	<frameset rows="83,*" cols="*" frameborder="NO" border="0" framespacing="0" bordercolor="#dbd7d0">
		<frame src="http://www.google.com/" name="top" scrolling="auto" noresize>
		<frame src="http://www.google.com/" name="body" scrolling="auto" marginheight=0 marginwidth=0>
	</frameset>
</html>
Here's the source code of the "Body" frame (MENU & MAIN):

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<TITLE id="PageTitle">Body Source</TITLE>
	</HEAD>
	<FRAMESET cols="160,*" id="frameContainer" frameborder="yes" bordercolor="#dbd7d0">
		<frame SRC="http://www.google.com/" id="menu" NAME="menu" SCROLLING=no marginheight=0 marginwidth=0></frame>
		<frame name="main" src="http://www.google.com/" scrolling="auto" marginheight=0 marginwidth=0></frame>
	</FRAMESET>
</HTML>
Image
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 16:37

Preliminary rewrite of the script in the original post to handle frames. So far tested only to one level of depth.

Code: Select all

#IfWinActive, ahk_class IEFrame
q:: ;internet explorer - get element under cursor
;show borders around, and get text from, element under cursor
;regardless of zoom percentage of 'Internet Explorer_Server' control
;it could potentially be incorporated into iWB2 Learner
IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"

CoordMode, Mouse, Screen
MouseGetPos, vMouseX, vMouseY,, hCtl, 3
WinGetClass, vCtlClass, % "ahk_id " hCtl
if !(vCtlClass == "Internet Explorer_Server")
	return
if !(oDoc := ComObject(9,ComObjQuery(Acc_ObjectFromWindow(hCtl),IID_IHTMLWindow2,IID_IHTMLWindow2),1).document)
	return
oWin := ComObject(9,ComObjQuery(oDoc,IID_IHTMLWindow2,IID_IHTMLWindow2),1)
oWB := ComObject(9,ComObjQuery(oWin,IID_IWebBrowserApp,IID_IWebBrowserApp),1)

vLogicalXDPI := oWB.document.parentWindow.screen.logicalXDPI
vDeviceXDPI := oWB.document.parentWindow.screen.deviceXDPI
vZoomRatio := vDeviceXDPI / vLogicalXDPI

;vWinX := oWin.screenLeft, vWinY := oWin.screenTop
;WinGetPos, vWinX2, vWinY2, vWinW2, vWinH2, ahk_class IEFrame
WinGetPos, vCtlX, vCtlY, vCtlW, vCtlH, ahk_id %hCtl%
vMouseX2 := (vMouseX-vCtlX)*(1/vZoomRatio)
vMouseY2 := (vMouseY-vCtlY)*(1/vZoomRatio)

oElt := oWin.document.elementFromPoint(vMouseX2, vMouseY2)

vOffsetX := 0, vOffsetY := 0
while (oElt.tagName = "IFRAME") || (oElt.tagName = "FRAME")
{
	ObjRelease(oWin)
	oWin := ComObject(9,ComObjQuery(oElt2:=oElt.contentwindow,IID_IHTMLWindow2,IID_IHTMLWindow2),1)
	ObjRelease(oElt2)
	oRect := oElt.getBoundingClientRect()
	vOffsetX += (oRect.left * vZoomRatio)
	vOffsetY += (oRect.top * vZoomRatio)
	vMouseX4 := vMouseX2 - oRect.left
	vMouseY4 := vMouseY2 - oRect.top
	oElt2 := oWin.document.elementFromPoint(vMouseX4, vMouseY4)
	ObjRelease(oElt)
	oElt := oElt2
	break
}

oRect := oElt.getBoundingClientRect()
vEltX := vCtlX + vOffsetX + (oRect.left * vZoomRatio)
vEltY := vCtlY + vOffsetY + (oRect.top * vZoomRatio)
vEltW := (oRect.right - oRect.left) * vZoomRatio
vEltH := (oRect.bottom - oRect.top) * vZoomRatio

JEE_Borders(vEltX, vEltY, vEltW, vEltH, 1000, "FFFF00")
MsgBox % oElt.tagName "`r`n" oElt.innerText
oDoc := oWin := oWB := oElt := oElt2 := oRect := ""
return
#IfWinActive
- The script uses the same logic as tank's script, while trying to account for the zoom level.
- The idea is that if the element under the cursor is a frame, you check the element under the cursor again, but this time relative to the frame, and you repeat this until you retrieve the first element under the cursor that is not a frame.
- There is some fiddly mathematics involved, re. working out the positions of the cursor and the frames, which I haven't fully worked out, but which I've sort of figured out intuitively.
- If you wish to provide some further html examples with nested frames, I could take a look.
- Note: I was concerned that it would be pointless to test your examples, as they would be frames with no elements in them, however, you get an error message when you run the files: 'This content cannot be displayed in a frame', and even a nice red X image element, that you can test the script on. So that was lucky, I don't know whether you were aware of that or not.
- Your examples, horizontal and vertical, were perfect, just what I needed to be able to do some effective tests.
- I searched around for websites that use frames or example webpages with frames. I didn't find any good examples. So I would welcome any.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
TheDewd
Posts: 1506
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 16:57

Your updated code works for the top iFrame, but the bottom iFrame is only showing the following:

oElt.tagName
FRAME

oElt.OuterHTML
<FRAME marginHeight=0 src="ThePageForThisFrame.html" name=main marginWidth=0>
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 17:04

- I just tested my script on the 2 html samples again, with them zoomed in, and they worked perfectly. So it's hard to say what the problem is.
- Perhaps you can tweak the script to make it work for you?
- Btw the script might try to handle nested frames, but I don't know if it will handle them correctly. So you could try break after one iteration of the while loop. [EDIT:] Ah, I left the break in there already.
- Btw your test relates to one of the example scripts that you posted ('First Source'), correct? Did it work correctly on the other example ('Body Source')?
- I tried both html examples separately. So if you want to me to test a different html example, please provide it explicitly.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
TheDewd
Posts: 1506
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 17:19

The website has a TOP and BOTTOM frame.

The TOP frame loads a page containing no frames.

The BOTTOM frame loads a page creating two more frames.

The BOTTOM frame has the two frames inside it, LEFT AND RIGHT.

Your script works on the TOP frame because there are no more levels.

The BOTTOM frame needs to go down more levels because the source of the BOTTOM frame is just to create the two additional frames for LEFT and RIGHT.

I would then need to go another level into the LEFT and RIGHT frame to get the content of those frames.

Hope that makes sense! The HTML I provided earlier is all I have at the moment.

I'm not sure why it shows that error when I try my examples in Internet Explorer -- Same error here... :-/
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer get element under cursor (show borders, show text) (any zoom percentage)

10 Nov 2017, 17:32

Well if there are more levels, you should remove the line 'break'. But I don't know if it will work correctly. If you provide some html examples that have frames within frames, I could experiment. I might try and create such an example myself, so that ultimately my script can handle frames within frames.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 119 guests