Accessing javascript object values from IE COM obect

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Accessing javascript object values from IE COM obect

31 Jan 2015, 09:12

Hi,

I have done a little testing, but it did not go like i was hoping, I tried to access a javascript objects values via an IE object using wb.document.parentWindow.object.array.item

And it gave me an error "0x80020006: Unknown name"
Image

But then, I looked it up and found some examples using a Gui with an activeX Control and tried that and it worked!?

I on win7 IE11 ahk v1.1.19.02 unicode 32bit

I made a little test setup that at least gives me the same result

None working IE object

Code: Select all

#SingleInstance force

html=
(
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<p id="p"></p>

<script type="text/javascript">
	function MsgBox(txt){alert(txt)};
    object = {};
    object.header = ["addressid", "contactid", "address1", "address2", "city", "state", "zip"];
    object.body = [["1234", "5678", "Lundebjerggårdsvej", "st. tv.", "skovlunde", "KBH", "2740"]];
    document.getElementById("p").innerHTML = object.body[0];
</script>

</body>
</html>
)

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true 
wb.navigate("about:blank")
while wb.busy
	continue
sleep 1000
wb.document.Write(html)
sleep 1000

msgbox % wb.document.parentWindow.object.body.0.toString()

wb.quit
wb:=""
ExitApp
Working ActiveX control

Code: Select all

#SingleInstance force

html=
(
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<p id="p"></p>

<script type="text/javascript">
	function MsgBox(txt){alert(txt)};
    object = {};
    object.header = ["addressid", "contactid", "address1", "address2", "city", "state", "zip"];
    object.body = [["1234", "5678", "Lundebjerggårdsvej", "st. tv.", "skovlunde", "KBH", "2740"]];
    document.getElementById("p").innerHTML = object.body[0];
</script>

</body>
</html>
)

Gui, Add, ActiveX, w500 h100 vwb, shell.explorer
gui, show, autosize
wb.navigate("about:blank")
while wb.busy
	continue
sleep 1000
wb.document.write(html)
sleep 1000

msgbox % wb.document.parentWindow.object.body.0.toString()
ExitApp
Any one who can tell me what i'm missing?
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: Accessing javascript object values from IE COM obect

31 Jan 2015, 13:55

Code: Select all

IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2

window := ComObj(9,ComObjQuery(wb,IID,IID),1)
MsgBox % window.object.boby.0.toString()
I believe it has to do with permissions on the window object. Another webpage shouldn't be able to call wb.document.parentWindow & access the window variables.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Accessing javascript object values from IE COM obect

31 Jan 2015, 16:06

Great! that works, thanks jethrow

My first thought was also that it was a permissions thing so I did try Querying for the window :) but was doing it wrong! Tried it like this ComObj(9,ComObjQuery(wb.document.parentWindow,IID,IID),1)

But great thanks
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Accessing javascript object values from IE COM obect

31 Jan 2015, 20:03

I'm guessing that if you query from wb.Document.parentWindow, the object you get is subject to the same restrictions, although it does give you a different pointer. Querying from wb.Document works, though.

One useful thing I found is that ComObjQuery(HTMLElement, IID, IID) will return the window which contains the element. But I suppose if you got the element via wb.Document.parentWindow, it would still be subject to the same restrictions.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 221 guests