Avatar of bhermer
bhermer

asked on 

Return Javascript values from a hooked IE window

Hi, I am trying to return a JS var from a hooked IE window. so for example:


'#  Get a new IE
Dim ie As New SHDocVw.InternetExplorerClass
wb = CType(ie, IWebBrowserApp)
wb.Visible = True
wb.Navigate("D:\index.htm", o, o, o, o)

'# Get an mshtml object
Dim HTMLDoc As mshtml.HTMLDocument= wb.Document

'# Get an IHTMLWindow2 from the frame sets
Dim f1 As mshtml.IHTMLWindow2 = CType(HTMLDoc.frames.item(2), mshtml.IHTMLWindow2)


'# HERE IS WHERE I NEED HELP
dim oObj =f1.execScript("function myFunc() { var a = document.getElementById('DYN');return a.innerHTML; };", "JScript")

What I need to do is have the value of a.innerHTML returned to the oOBJ and eventually into a string, I know that exeScript doesnt return a value, but this article here, someone has done so using a language I dont understand. Help please!

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3631410&SiteID=1
Visual Basic.NETC#.NET Programming

Avatar of undefined
Last Comment
bhermer
ASKER CERTIFIED SOLUTION
Avatar of Cem Türk
Cem Türk
Flag of Türkiye image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Cem Türk
Cem Türk
Flag of Türkiye image

or you can use following without modifying your code
msgbox f1.document.documentElement.getElementById("DYN").innerHTML
Avatar of bhermer
bhermer

ASKER

Hi Cem_Turk,

What you say is correct, but, if the html of the element DYN starts as 'abc' but is then changed dynamically via javascript to '123' then the VB solution returns the original html of the element, not the dynamic element.

The JS version returns the dynamic html, and that is what I need.
Avatar of Cem Türk
Cem Türk
Flag of Türkiye image

no it changes dynamically too, note that the code above not deals with viewsource of the page.. it access the page through DOM and you can modify anything as well as you can get anythings latest state. If innerHTML keeps changing you will get the latest value when you run the script. I can help more if you tell what exactly you are trying to do.
Avatar of bhermer
bhermer

ASKER

cem_turk, your are a genius, thanks. The problem I was having is I was trying to deal with an IHTMLWindow2 and I think that is a ByVal object, where as  when I re-class f1.document as an mshtml.HTMLDocument I think I am getting a ByRef object i.e

Dim HTMLDoc As mshtml.HTMLDocument
HTMLDoc = f1.document

I get the dynamic code from the HtmlDOC object.

Thank you very much, wished I had asked sooner, spent a day on this yesterday!
Avatar of Cem Türk
Cem Türk
Flag of Türkiye image

your welcome, i have spent 3 years coding stuff like that :)
Avatar of bhermer
bhermer

ASKER

Sorry, let this one slip, apolgies and thanks cem_turk
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo