Microsoft WebBrowser control

  • Thread starter Thread starter Bill Cousert
  • Start date Start date
Bill Cousert said:
I have a Windows Form that uses the Microsoft WebBrowser control. If I load
an HTML file into the control that contains Jscript code, can the Jscript
code call a C# function in my Windows Form?

Hi Bill,

Try adding your C# object as the "window.external" object. Then JScript
should be able to manipulate it.

Peter
 
Peter Torr (MS) said:
Hi Bill,

Try adding your C# object as the "window.external" object. Then JScript
should be able to manipulate it.

Hi Peter,

Would I do this by adding a reference? Assume my function is named test. How
would I call it from JScript?


Thanks,

-Bill Cousert
(e-mail address removed)
 
Bill Cousert said:
Hi Peter,

Would I do this by adding a reference? Assume my function is named test. How
would I call it from JScript?

Actually, I'm not sure how easy it will be to use the external object in C#
with WinForms. Looking at:

http://msdn.microsoft.com/workshop/browser/overview/overview.asp

it seems you have to do work in an DocUIHost interface which (presumably)
WinForms implements for you. Maybe you can figure out a way around that.

Anyway, the next best option is to call into IE to get a handle on the
script block, then use Reflection to invoke a member on the script that will
accept a callback object (your C# object) for later use. Kind of messy, but
it should work.

Peter
 
Peter Torr (MS) said:
Actually, I'm not sure how easy it will be to use the external object in C#
with WinForms. Looking at:

http://msdn.microsoft.com/workshop/browser/overview/overview.asp

it seems you have to do work in an DocUIHost interface which (presumably)
WinForms implements for you. Maybe you can figure out a way around that.

Anyway, the next best option is to call into IE to get a handle on the
script block, then use Reflection to invoke a member on the script that will
accept a callback object (your C# object) for later use. Kind of messy, but
it should work.

Peter
Thank you! I see I have my work cut out for me. I will post the results when
I figure this out.
 
Back
Top