tag - BHO exposing javascript method works in IE 9+ but fails in earlier versions
new in html (2)
Found an answer on Stack Overflow. You just have to change code to this:
public void InjectScriptResource(dynamic window)
{
var windowEx = (IExpando)window;
if (windowEx.GetProperty("signJson", BindingFlags.Default) == null)
{
// windowEx.AddProperty("signJson");
PropertyInfo p = windowEx.AddProperty("signJson");
// window.signJson = this;
p.SetValue(windowEx, this);
}
}
https://code.i-harness.com
I'm making a BHO that exposes method to JavaScript.
It works okey in IE 9 and IE 10, but fails in IE 8 with RuntimeBinderException: "mshtml.HTMLWindow2Class" does not contain "signJson"
.
Code is mostly based on live reload IE extention.
Here is a way that function is injected into window:
public void InjectScriptResource(dynamic window)
{
var windowEx = (IExpando)window;
if (windowEx.GetProperty("signJson", BindingFlags.Default) == null)
{
windowEx.AddProperty("signJson");
window.signJson = this;
}
}
What's different about about mshtml.HTMLWindow2Class
in IE 8 from IE 9? What is a proper way to inject method into it?
function in c# bho not exposed when loading sites in localhost
i already found the solution to my problem... just have to change some part in onDocumentComplete function...
Solution
Change below code:
public void OnDocumentComplete(object pDisp, ref object URL) {
document = (HTMLDocument)webBrowser.Document;
dynamic window = webBrowser.Document.parentWindow;
IExpando windowEx = (IExpando)window;
windowEx.AddProperty("sEnhancer");
window.sEnhancer = this;
}
to:
public void OnDocumentComplete(object pDisp, ref object URL) {
document = (HTMLDocument)webBrowser.Document;
dynamic window = webBrowser.Document.parentWindow;
IExpando windowEx = (IExpando)window;
PropertyInfo p = windowEx.AddProperty("sEnhancer");
p.SetValue(windowEx, this);
}
solution was based from this post BHO exposing javascript method works in IE 9+ but fails in earlier versions