简体   繁体   中英

Call C# BHO method from javascript

I need to call a C# BHO method from javascript

I have followed the solution given in this question

I get the error:

'mshtml.HTMLWindow2Class' does not contain a definition for 'myExtension'.

I cannot assign:

dynamic window = browser.Document.parentWindow; 

as parentWindow is undefined, I have to cast to (mshtml.IHTMLDocument2) and (mshtml.IHTMLWindow2)

Does anyone have a full working example I could refer to or any help or alternative solutions

I've the same problem. And the following fix seems work in my BHO:

dynamic window = _webBrowser.Document.parentWindow;
var windowEx = (IExpando)window;
PropertyInfo p = windowEx.AddProperty("myExtension");
p.SetValue(windowEx, this);

instead of:

dynamic window = _webBrowser.Document.parentWindow;
var windowEx = (IExpando)window;
PropertyInfo p = windowEx.AddProperty("myExtension");
window.myExtension = this;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM