سؤال

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?

هل كانت مفيدة؟

المحلول

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);
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top