0

I use a VBA macro (in Excel) to navigate a website and gather some data from a webpage. In this case Excel is just a container but I didn't have any other easy way to write a program :) Now I have found the portable version of SharpDevelop and I'd like to rewrite this small application in .NET using C# but I have a problem.

In VBA I can access Javascript variables directly using, for example:

result = WebBrowser1.Document.frames(0).tabTime

where WebBrowser1 is my WebBroser component and tabTime is a Javascript array. The type of result is Variant/string, but that's OK, I can manipulate that string easily.

In .NET I have to add a Window to reach the frame, like that:

HtmlWindow myFrame = webBrowser1.Document.Window.Frames[0];

Now I have the frame but I didn't find a way to access the javascript variable tabTime. I have already tried with no success:

myFrame.tabTime;
myFrame.Document.tabTime;
myFrame.DomWindow.tabTime;
dynamic p = myFrame.Document.InvokeScript("eval", new object[] { "tabTime" });

Any ideas?

Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
Marco
  • 17
  • 4
  • Maybe this? `myFrame.Document.Window.DomWindow.execscript("tabTime", "JavaScript")` – Ryan Wildry Mar 06 '17 at 17:58
  • http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control – Tim Williams Mar 06 '17 at 18:00
  • @RyanWildry: I've investigated DomWindow and it seems it's an object with no `execscript` method. In fact it should be casted to IHTMLWindow2, IHTMLWindow3, or IHTMLWindow4. These interfaces are unmanaged and to be used I should create a reference to the unmanaged MSHTML.dll. I would prefer to use the framework. – Marco Mar 09 '17 at 21:52
  • @TimWilliams: since I don't want to inject javascript nor execute scripts, could you please point me to the part of that post related to my need? – Marco Mar 09 '17 at 21:56

0 Answers0